docs
/
AI skills

Delivery zones and agents

Set up local delivery in Studio › Logistics. Draw the service areas (zones) with their own prices and driver pay, set the default pricing tiers and surge rules, quote a delivery, and take a driver from sign-up through approval, online, suspension or rejection. What each setting changes in a quote, and what is refused.

Logistics in Studio (/logistics) runs on-demand local delivery. It has these tabs:

  • Dashboard
  • Map
  • Zones: where you deliver.
  • Agents: the drivers.
  • Jobs
  • Merchants
  • Config: the pricing.

The operator endpoints are under logistics/delivery/* and the driver app's under client/logistics/* (appengine logistics/delivery.controller.ts, delivery.service.ts, delivery-client.service.ts), called with call_appengine. Zones and the config are records (delivery_zone, delivery_config), saved with repo_create and repo_update as the screens do.

This page sets up where you deliver, what it costs and who drives. Creating, offering and driving jobs, payments and driver payouts are in the Logistics and delivery reference. Shipping by carrier is a different thing; see Shipping rates and settings.

How a price is worked out for a set of stops (calculateJobPricing):

  1. Distance. It's the street route through the stops when the org has a Google Maps key (routeSource: google), else a straight line (haversine).
  2. The config's tiers. Each distance band has a flat fee or a per-mile rate.
  3. Zone overrides.
    • The config's own per-zone override (zones[]) is applied for the delivery's zone.
    • The zone record's own Pricing (baseFee + perMile × miles) takes over from the tiers when it's set.
  4. The minimum fee. The zone's minimum applies, else the config's.
  5. Surge. The config's surge rules multiply the price; the highest multiplier that applies wins.
  6. Driver pay. It's the zone's Payout (driverBaseRate + driverPerMile × miles) when set. Otherwise it's the config's share of the price (75% by default), never under the minimum pay (10 by default).

The delivery's zone is the zone of the first stop.

Ask first

  • Where do you deliver? A radius around a place, a drawn area, or a list of zip codes, cities, states or countries.
  • What does the customer pay? Per zone or for everywhere: a base fee, a per-mile rate and a minimum.
  • What does the driver get? A share of the price, or a base plus a per-mile rate in a zone. What is the least a driver gets?
  • Any surge? Which days and hours, which zones, and how much (×1.5…).
  • For a driver: approve, suspend or reject, and the note or reason to give them.

Steps

1. Studio › Logistics › Config: the default pricing

The first read of the config creates one named Default if the org has none. The call is GET logistics/delivery/config, or ?name=<config>. Tested, the Default was:

SettingDefault
Distance tiers (pricing.tiers)up to 5.5 mi flat 15; to 10.5 mi 2.85/mi; to 20.5 mi 3.15/mi; beyond 3.45/mi
Minimum fee (pricing.minimumFee)15
Driver share (driverPayout.percentage)75%
Driver minimum (driverPayout.minimumPay)10
Tips to the driver (driverPayout.tipShare)100%

Each tier's rate counts only for the miles inside it. Tested: a 32.42-mile delivery with no zone pricing cost 101.86, and the driver got 76.40 (75%).

Surge rules (surgeRules) are a list:

[ { "name": "Friday nights", "enabled": true, "multiplier": 1.5,
    "conditions": { "zones": ["dallas-core"], "timeWindows": [ { "days": ["friday"], "startTime": "18:00", "endTime": "23:00" } ] } } ]
  • A rule with no time windows applies at all times.
  • The surge fee is the price × (multiplier − 1). It's added to what the customer pays. Driver pay doesn't change unless it's a share of the price.

Hands on: change one part of the config with repo_update (POST repository/update-partial/delivery_config/<sk>), using a dot-path key such as { "data.surgeRules": [...] }.

Sending data: {...} to update-partial replaces the whole config: tiers, payout and everything else. Send only the dot-path key you're changing, and read the config back.

Stop: a pricing change applies to every quote and new job from now on. Show the old and new values, and wait for yes.

Check: POST logistics/delivery/quote for a known route gives the expected price (step 3).

Surge times are the server's clock, not the business's time zone. A window of 18:00–23:00 is matched against the engine's local time. Check a quote at the time you expect it to apply.

2. Studio › Logistics › Zones: add a zone

Zones lists the service areas. A zone's form has four tabs:

  • Geography: the zone type and its area.
  • Details: name, title, description.
  • Operations: hours, holidays and restrictions.
  • Pricing: Customer Pricing and Driver Payout.

A new zone is inactive. Press Activate when it's ready. Only active zones count.

Hands on: repo_create on delivery_zone:

{ "name": "dallas-core", "title": "Dallas core", "status": "active",
  "geography": { "type": "radius", "center": { "lat": 32.7767, "lng": -96.797 }, "radius": 10 },
  "pricing": { "baseFee": 5, "perMile": 2, "minimumFee": 8 },
  "payout": { "driverBaseRate": 3, "driverPerMile": 1, "driverMinimum": 6 } }

The zone's name is its key. Surge rules, the config's zone overrides and jobs refer to it.

geography.typeAreaMatches on
radiuscenter: { lat, lng }, radius in milesthe stop's coordinates
polygonpolygon: [ { lat, lng }, … ], 3 points or morethe stop's coordinates
zipcodeszipcodes: ["76102", …]the stop's zip code
citiescities: [ { city, state? } ]city, and state when given
statesstates: [ { state } ]the stop's state, as text
countriescountries: ["US", …]country, with US/USA/United States treated as one

Zones are tried in list order, and the first match wins. When the org has no active zones, every address is served. When it has some, a stop outside them all is refused.

Stop: activating a zone, or changing its area or pricing, changes where you deliver and what it costs. Show the zone, and wait for yes.

Check: GET logistics/delivery/zones lists active zones; ?status=inactive lists the others. A quote with a stop inside the zone names it (step 3).

A state zone must use the same text as the address. Google geocoding gives the short code ("TX"), and the match is plain text. A zone saved with "Texas" never matches a geocoded address. Enter states as their two-letter codes.

The zone's Operations tab isn't used by quotes or jobs. Operating hours, holidays, restrictions and the zone's own surge settings are saved but never read by the server. Put surge in the config's rules (step 1).

3. Quote a delivery

POST logistics/delivery/quote { stops, configName? } geocodes each stop, checks that it's inside a zone, and prices the route:

{ "stops": [ { "type": "pickup",  "location": { "lat": 32.7767, "lng": -96.797 } },
             { "type": "dropoff", "location": { "address": "1500 Marilla St, Dallas, TX 75201" } } ] }

The location can be coordinates, an address string, or an address object with city, state and zipCode. A zip, city or state zone matches only when the stop has those parts: from an address, or sent as zipCode, city and state on the location.

Tested results:

  • Inside a zone with pricing: 4.01 miles at 5 + 2 × 4.01 = 13.01. The driver got 3 + 1 × 4.01 = 7.01.
  • Outside every zone: valid: false, with "Location is outside our delivery service area".
  • A zip-code zone without pricing: a Fort Worth pickup sent with zipCode: "76102" matched it. With no zone pricing, it fell back to the tiers.
  • Surge: a ×1.5 rule limited to the zone added a surge fee of 6.51, for a total of 19.52. The driver's zone payout stayed 7.01.

Check: valid: true, each stop's zone and serviceable, and quote.customerPays and quote.driverPay.total. routeSource says whether the street route was used.

GET logistics/delivery/zones/lookup?lat=&lng= only finds radius and polygon zones. It passes no address parts, so zip, city, state and country zones never match it (tested). To test those, use a quote with the address.

4. Studio › Logistics › Agents: approve a driver

A driver signs up from the driver app with POST client/logistics/register (vehicle type, make, model, plate…). The agent record:

  • is created with the driver's customer id as its id;
  • starts with status Pending and availability Offline;
  • sends the driver an "application received" email.

A second sign-up is refused: 409 "You are already registered as a driver". An operator can also add an agent from Agents, linked to an existing customer.

Open the agent. The buttons are Approve, Suspend, Reactivate (the same as approve), Online/Offline, Assign (a job) and Recalc (performance).

ActionCallWhat changes
ApprovePUT logistics/delivery/agents/<id>/approve { notes? }Approved. The note goes into the approval history, and an "approved" email goes to the driver. Tested.
SuspendPUT …/<id>/suspend { reason }Suspended and offline. A "suspended" email goes out. Tested.
RejectPUT …/<id>/reject { reason }Rejected, with rejectionReason, and offline. A "rejected" email goes out. Tested. There's no Reject button on the screen.

Stop: each of these emails the driver. Show the driver, the action and the note or reason. Wait for yes.

What the driver can do depends on the status (tested):

Driver's statusGoing online or sending a location
No agent record"Agent profile not found. Please register first."
Pending403 "Your driver application is pending approval…"
Suspended403 "Your driver account has been suspended. Please contact support."
Approved or ActiveAllowed. They show in GET logistics/delivery/agents/online?lat=&lng=&radius= (miles).

Check: the agent reads Approved, and the approval is in its history. Once the driver goes online, they're in the online list. Tested: a driver online in Dallas was found within 5 miles of downtown, and an Austin search found none.

A self-registered driver's name is a generated id, not their name. The agent is named like delivery_agent-1792545917867-ycq9m8t9. The approval, suspension and rejection emails greet the driver by that name. Before approving, set the agent's name to the driver's real name (repo_update, name).

The admin Online button works on any driver, but the online list only shows approved and active ones. Tested: a pending driver set online by an operator didn't appear in agents/online. Assigning or offering a job from the operator side doesn't check the driver's status either. Approve a driver before giving them work.

Who's driving

  • GET logistics/delivery/agents lists agents. It filters by status, availability and type.
  • GET logistics/delivery/agents/online lists approved and active drivers who are online, optionally near a point.
  • GET logistics/delivery/agents/<id> returns one agent. Use the agent's real id; anything else gives a 500 error.
  • GET logistics/delivery/agents/<id>/available-jobs lists the jobs a driver could take.
  • Recalc (PUT …/<id>/recalculate-performance) recounts the driver's performance from their jobs.

When it's done

  • Each zone you serve is Active, with its area, and its pricing and payout where they differ from the config.
  • The config's tiers, minimum, driver share and surge rules are what was agreed.
  • A quote for a known route inside each zone gives the expected price and driver pay.
  • Each driver who should work reads Approved. The others read Pending, Suspended or Rejected.

What it can't do yet

  • Zone hours, holidays and restrictions aren't used (step 2).
  • zones/lookup ignores zip, city, state and country zones (step 3).
  • A surge rule limited to some zones also applies to a delivery with no zone. When no zone matched (only possible when the org has no active zones), every enabled rule applies.
  • Each quote looks the route up twice, once for the quote and once for the price, so the Google Maps usage counts twice.
  • The schema's payout field names (basePay, perMile, minimumPay) are not the ones the zone form and the server use (driverBaseRate, driverPerMile, driverMinimum). Use the latter.

Don'ts

  • Don't approve, suspend or reject a driver without a yes. Each sends them an email.
  • Don't activate a zone, or change pricing or surge, without a yes.
  • Don't send data: {...} in an update to the config or a zone. Use dot-path keys.
  • Don't set a driver online, or assign them a job, unless they're approved.
  • Don't create test jobs against real drivers. A job offered to a driver reaches their app.