-> Directs

Directs describe a pickup and a delivery which are planned within the same tour without an intermediate stop at the depot. Meaning, the route optimization ensures that a specific delivery is scheduled on the exact same route as a desired pickup.
To define directs you need to create a pickup_ref_id for the delivery location. The pickup_ref_id of the delivery must always be identical to the custom_id of the pickup, in order to connect these two shipments.
It is important that both shipments (pickup and delivery) have the same priority and load parameter. The pickup should have positive load signs (or be defined with shipment_type=pickup) and the delivery should have negative load signs (or be defined with shipment_type=delivery).
You also need a time window defined by pdt_from and pdt_to in the ISO datetime format. 'pdt' describes the 'planned delivery time', i.e. the time window in which the goods are expected to arrive at its destination. If you don't provide a time window, we default to the earliest time to leave the depot and the latest time to return to the depot.

import requests
import json

auth_header = {"Authorization": 'JWT ' + token}
api_url = "https://<your company name>.prod.smartlane.io/api/calcroute/optimized/timewindow"

payload = {
  "deliverydata": [
         {
            "custom_id": "id_1",
            "customernr": "nr_1",
            "street": "Centrumstrasse 69",
            "postalcode": "45307",
            "country": "DE",
            "city": "Essen",
            "load": 45.0,
            "load_2": 20,
            "load_3": 15,
            "shipment_type": "pickup",
            "shipment_priority": "6",
            "pdt_from": "2025-12-23T08:00:00+00:00",
            "pdt_to": "2025-12-23T18:00:00+00:00",
            "contactcompany": "customer_1"
         },
         {
            "custom_id": "id_2",
            "customernr": "nr_2",
            "street": "JOHANNISKIRCHSTR. 1",
            "postalcode": "45329",
            "country": "DE",
            "city": "Essen",
            "load": 45.0,
            "load_2": 20,
            "load_3": 15,
            "shipment_type": "delivery",
            "shipment_priority": "6",
            "pdt_from": "2025-12-23T08:00:00+00:00",
            "pdt_to": "2025-12-23T18:00:00+00:00",
            "contactcompany": "customer_2",
            "pickup_ref_id": "id_1"
         }
      ],
      "vehicles": [
         {
            "custom_id": "id_1",
            "name": "Vehicle_1",
            "vehicle_class": "truck",
            "capacity_1": 15000,
            "capacity_2": 2200,
            "capacity_3": 99999,
            "daily_rate": 250,
            "km_rate": 0.35,
            "traveltime_factor": 1.4,
            "departure_time_from": "2025-12-23T06:00:00+00:00",
            "departure_time_to": "2025-12-23T07:00:00+00:00",
            "return_time_to": "2025-12-23T16:00:00+00:00",
            "max_tour_duration": 540,
            "depot_location": {
              "street": "Elsenheimerstraße",
              "housenumber": "45",
              "postalcode": "80687",
              "city": "München" }
         }
      ]
   }

response = requests.post(api_url, headers=auth_header, json=payload)
print (response.text)
print (response.status_code)