Delivery optimization task

How to use Geoapify Route Planner API to solve a delivery route optimization task

by Geoapify

HTML

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/maplibre-gl.css">
<script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
<div id="my-map"></div>

CSS

body {
      margin: 0;
      padding: 0;
    }

    #my-map {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 100%;
    }

JavaScript

// The API Key provided is restricted to JSFiddle website
// Get your own API Key on https://myprojects.geoapify.com
const myAPIKey = "6dc7fb95a3b246cfa0f3bcef5ce9ed9a";

// create a map object
const map = new maplibregl.Map({
  container: 'my-map',
  center: [9.193347, 48.894660],
  zoom: 13,
  style: `https://maps.geoapify.com/v1/styles/klokantech-basic/style.json?apiKey=${myAPIKey}`,
});
map.addControl(new maplibregl.NavigationControl());

// this object describes 
const deliveryOptimizationInput = {
  "mode": "drive",
  "agents": [
    {
      "start_location": [
        9.184216439347189,
        48.89244305
      ],
      "time_windows": [
        [
          0,
          10800
        ]
      ]
    },
    {
      "start_location": [
        9.18674538469634,
        48.89783585
      ],
      "time_windows": [
        [
          0,
          10800
        ]
      ]
    },
    {
      "start_location": [
        9.1927926,
        48.8967017
      ],
      "time_windows": [
        [
          0,
          10800
        ]
      ]
    }
  ],
  "shipments": [
    {
      "id": "order_1",
      "pickup": {
        "location_index": 0,
        "duration": 120
      },
      "delivery": {
        "location": [
          9.183412901202828,
          48.8899988
        ],
        "duration": 120
      }
    },
    {
      "id": "order_2",
      "pickup": {
        "location_index": 0,
        "duration": 120
      },
      "delivery": {
        "location": [
          9.19023209753983,
          48.893762699999996
        ],
        "duration": 240
      }
    },
    {
      "id": "order_3",
      "pickup": {
        "location_index": 0,
        "duration": 120
      },
      "delivery": {
        "location": [
          9.19023209753983,
          48.893762699999996
        ],
        "duration": 240
      }
    },
    {
      "id": "order_4",
      "delivery": {
        "location_index": 0,
        "duration": 240
      },
      "pickup": {
        "location":...