POST /cost

Prices one route. You send the stops in the order the vehicle serves them, the vehicle that drives the route and, optionally, the same settings as POST /solve_routes. The server answers with the route's cost, miles and minutes, whether the route is feasible, and when it reaches each stop. Nothing is solved or saved.

POST https://routing.lu.app/cost
Content-Type: application/json

The cost is the one the solver and the route editor give the same route: the server builds the same model as a solve, with the same road distances and drive times from OSRM, each leg rounded the same way, and prices it the same way. A route from a saved plan, sent with that plan's input, comes back with the same RouteSummary the plan saved for it.

Quick example

curl -X POST https://routing.lu.app/cost \
  -H 'Content-Type: application/json' \
  -d '{
    "vehicle_type": "16",
    "stops": [
      {"stop_id": "fde871df-0201-4e35-bdc1-4ce355fd2a2f", "store_reference": "2794",
       "customer_name": "Sally Beauty WA", "store_lat": 44.969938, "store_lng": -123.030083,
       "schedule_window_start": "20:00", "schedule_window_end": "09:00", "weight": 691.0, "pallet_count": 2,
       "type": "delivery", "avg_unload_time": 30, "allowed_vehicles": null, "receivable_item_amount": 302.08}
    ]
  }'
{
  "vehicle_type": "16' box",
  "depot": "Depot",
  "cost": 541.67,
  "summary": {"duration": 220, "miles": 190, "cost": 541.67, "cost_gas": 285.0, "cost_maint": 38.0,
              "cost_wage": 218.67, "flat_added": 0, "weight": 691, "pallets": 2,
              "pickup_weight": 0, "pickup_pallets": 0},
  "linehaul": null,
  "feasible": true,
  "problems": [],
  "notes": [],
  "overtime": 0,
  "overtime_penalty": 0,
  "stops": [{"name": "[fde871df-0201-4e35-bdc1-4ce355fd2a2f] Sally Beauty WA, 2794", "arrival": 190, "late": 0}],
  "warnings": []
}

(The numbers above are illustrative.)

Request body

A JSON object with vehicle_type, stops, an optional depot, and any of the solver settings. Any other field, job_id included, is rejected with a 400.

Field Type Required Meaning
vehicle_type "26" | "16" | "van" yes The vehicle that drives the route, as a vehicle code.
stops (Stop | "reload")[] yes The route's stops, in the order they're served. Each is a Stop, exactly as for /solve_routes, or the string "reload" for a trip back to the depot to reload. Each stop may appear once.
depot string no With allow_linehaul and linehaul_depots: the name of the linehaul depot whose fleet drives the route. Every stop then rides that depot's linehaul, and the linehaul's cost is added. Left out, the route runs from Auburn.

A "reload" at the start or end of the route, or straight after another one, isn't a trip and is ignored, as in the editor. The route may reload at most max_reload_<vehicle_type> times.

Settings

Every /solve_routes setting is accepted, with the same defaults, so a /solve_routes body (with vehicle_type added) can be sent as is. These change the cost or the result:

Setting Effect on the route
round_trip, cost_is_round_trip Whether the drive back to the depot counts toward miles, duration and cost.
capacity_* The vehicle's load limit. Over it, the route is infeasible.
work_duration_*, max_overtime_*, enable_vehicle_work_duration The shift and overtime limit: overtime, its overtime_penalty, and infeasible past shift + overtime.
max_reload_* How many "reload"s the route may have. Above 0 needs round_trip: true, since the default is one-way.
num_available_* 0 for vehicle_type is rejected, since the fleet then has no such vehicle.
allow_linehaul, linehaul_depots Needed for depot. Each depot's cost_per_pallet prices its linehaul, and pallet_limit and service_radius decide which stops may ride it.
objective, runtime, no_improvement and seed only steer a search, so they have no effect here: cost is
always in dollars.

Response

200 OK: CostResponse

Field Type Meaning
vehicle_type string The vehicle's name, e.g. "16' box", or "Portland 16' box" from a linehaul depot.
depot string The depot the route runs from: "Depot" for Auburn, or the linehaul depot's name.
cost number Dollar cost of the route plus, from a linehaul depot, its linehaul, rounded to cents.
summary RouteSummary The route's RouteSummary: duration, miles, cost (the route alone, without the linehaul) and its parts, and the lbs and pallets delivered and picked up.
linehaul object | null From a linehaul depot only: its depot, the stops it carries, their pallets and weight, cost_per_pallet, cost, max_pallets and over_cap, as in the /solve_routes response's linehaul. null from Auburn.
feasible boolean Whether the route keeps to every limit: capacity, delivery windows, and shift + overtime.
problems string[] Why the route is infeasible, in the editor's words, e.g. "late for the delivery window at stop 3 (12 min)". Stops are numbered from 1 in route order. Empty when feasible.
notes string[] Overtime, which is allowed, e.g. "45 min overtime".
overtime integer Minutes past the shift.
overtime_penalty number What the solver charges for that overtime with objective: "cost", in dollars ($100 an hour). It only steers the solver and isn't in cost.
stops (object | "reload")[] Each visit in route order: a stop as name, arrival (minutes after the 00:00 depot departure that service starts) and late (minutes past its window, else 0), or "reload".
warnings string[] The same pre-solve warnings as /solve_routes: stops no allowed vehicle can serve at all.

Errors: ErrorResponse

Every error is {"error": "<message>"}. On top of the /solve_routes errors for the stops and settings (the job_id and 409 ones aside):

Status When
400 vehicle_type is missing or not a vehicle code.
400 stops has no stop, has an entry that's neither a stop object nor "reload", or has a stop twice.
400 A stop isn't allowed on vehicle_type by its allowed_vehicles. The message lists each such stop.
400 More reloads than max_reload_<vehicle_type>, or any max_reload_* above 0 without round_trip: true.
400 num_available_<vehicle_type> is 0.
400 depot without allow_linehaul, a depot not in linehaul_depots, or a stop that may not ride that depot's linehaul (a delivery of 1 to pallet_limit pallets within service_radius).
405 The method isn't POST.
500 Any other failure, such as a setting of the wrong type.