# Create plan

Create a saved routing plan using vehicles, jobs and geographic coordinates.

> **Proposed public API.** The direct submission contract is a design proposal. Its examples are illustrative.

## Request

Send all timestamps in UTC and end each one with an uppercase `Z`. The `Z` means UTC. Responses use the same format.

| Field | Type | Description |
| --- | --- | --- |
| name | string | Plan label |
| expiryHours | integer | 1, 24 or 48; default 24 in current implementation |
| vehicles | array of objects | Vehicle definitions |
| jobs | array of objects | Service visits or shipments with linked pickup and delivery stops |

The van can carry four pallets and 800 kg. Each job specifies its load as `[pallets, kilograms]`. The van also has a 30-minute break that can start between 11:00 and 12:00 UTC (12:00 to 13:00 in Stockholm on December 1).

- [Nested field definitions](./model.md)

```json
{
  "name": "Stockholm service visits",
  "expiryHours": 24,
  "vehicles": [
    {
      "id": "van-1",
      "startLocation": {
        "latitude": 59.3326,
        "longitude": 18.0649
      },
      "endLocation": {
        "latitude": 59.347,
        "longitude": 18.038
      },
      "capacity": [4, 800],
      "breaks": [
        {
          "durationMinutes": 30,
          "timeWindow": {
            "start": "2026-12-01T11:00:00Z",
            "end": "2026-12-01T12:00:00Z"
          }
        }
      ],
      "timeWindow": {
        "start": "2026-12-01T07:00:00Z",
        "end": "2026-12-01T16:00:00Z"
      }
    }
  ],
  "jobs": [
    {
      "id": "job-1",
      "location": {
        "latitude": 59.34,
        "longitude": 18.05
      },
      "serviceDuration": 5,
      "load": [1, 250],
      "timeWindow": {
        "start": "2026-12-01T08:00:00Z",
        "end": "2026-12-01T15:00:00Z"
      }
    },
    {
      "id": "job-2",
      "location": {
        "latitude": 59.345,
        "longitude": 18.045
      },
      "serviceDuration": 10,
      "load": [2, 300]
    }
  ]
}
```

## Example locations

The example uses four points in central Stockholm, Sweden. The vehicle defines where the route starts and ends. Each job defines a place to visit. Array indexes start at zero, so `jobs[0]` is the first job listed in the request. The optimiser determines the visit order.

| Location | JSON field | Area | Map pin (latitude, longitude) |
| --- | --- | --- | --- |
| Van start | `vehicles[0].startLocation` | Near Sergels torg | [59.3326, 18.0649](https://www.openstreetmap.org/?mlat=59.3326&mlon=18.0649#map=17/59.3326/18.0649) |
| Van end | `vehicles[0].endLocation` | Northwest of Odenplan | [59.3470, 18.0380](https://www.openstreetmap.org/?mlat=59.3470&mlon=18.0380#map=17/59.3470/18.0380) |
| Job `job-1` | `jobs[0].location` | South of Odenplan | [59.3400, 18.0500](https://www.openstreetmap.org/?mlat=59.3400&mlon=18.0500#map=17/59.3400/18.0500) |
| Job `job-2` | `jobs[1].location` | Northwest of Odenplan | [59.3450, 18.0450](https://www.openstreetmap.org/?mlat=59.3450&mlon=18.0450#map=17/59.3450/18.0450) |

[See all four locations in Google Maps](https://www.google.com/maps/dir/?api=1&origin=59.3326,18.0649&destination=59.3470,18.0380&waypoints=59.3400,18.0500%7C59.3450,18.0450&travelmode=driving). The map shows the jobs in request order.

## Pickup and delivery example

To collect one pallet weighing 250 kg at the first Stockholm location and deliver it to the second, replace the two service visits in the request above with this `jobs` array. The same vehicle visits both stops, with pickup first. Specify the shipment’s `load` once. Each stop has its own `serviceDuration` in minutes.

For a shipment, omit `jobs[0].location`. Put the two sets of coordinates in `jobs[0].pickup.location` and `jobs[0].delivery.location`.

```json
{
  "jobs": [
    {
      "id": "shipment-1",
      "load": [1, 250],
      "pickup": {
        "location": { "latitude": 59.34, "longitude": 18.05 },
        "serviceDuration": 5
      },
      "delivery": {
        "location": { "latitude": 59.345, "longitude": 18.045 },
        "serviceDuration": 10
      }
    }
  ]
}
```

Allow 5 minutes to load the pallet and 10 minutes to unload it. Travel time between the stops is calculated separately.

## Example call

```bash
API_BASE=https://api.coordigator.io
curl --fail-with-body -sS "$API_BASE/plans" \
  -H "Authorization: Bearer $COORDIGATOR_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @plan.json
```

## 201 Created

```json
{
  "planId": "11111111-1111-4111-8111-111111111111",
  "expiresAt": "2026-12-02T08:00:00Z"
}
```

The plan ID identifies the saved plan. `expiresAt` is the UTC time when the plan expires. Access material and Dispatcher handoff fields must be designed and verified before release.
