> ## Documentation Index
> Fetch the complete documentation index at: https://twigz.arqqin.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delivery Zones

> Manage store delivery areas, fees, and timing

## Overview

The Delivery Zones API allows stores to configure their delivery coverage areas with customizable fees and timing for different locations. This system enables flexible delivery pricing and service area management.

**Location:** `convex/stores/deliveryZones.ts`

## Get Store Delivery Zones

<ParamField path="cityId" type="Id<'cities'>">
  Optional city filter
</ParamField>

<CodeGroup>
  ```typescript TypeScript theme={null}
  const zones = await convex.query(api.stores.deliveryZones.getStoreDeliveryZones, { 
    cityId: "ct123456789" 
  });
  ```

  ```javascript JavaScript theme={null}
  const zones = await convex.query("stores.deliveryZones.getStoreDeliveryZones");
  ```
</CodeGroup>

<ResponseExample>
  ```json Response theme={null}
  [
    {
      "_id": "dz123456789",
      "storeId": "j123456789",
      "city": "ct123456789",
      "cityName": "Dubai",
      "deliveryFee": 5.00,
      "deliveryTime": 30,
      "deliveryTimeUnit": "minutes",
      "areas": [
        {
          "area": "ar123456789",
          "areaName": "Marina",
          "deliveryFee": 5.00,
          "deliveryTime": 25,
          "deliveryTimeUnit": "minutes"
        },
        {
          "area": "ar987654321",
          "areaName": "JBR",
          "deliveryFee": 7.00,
          "deliveryTime": 35,
          "deliveryTimeUnit": "minutes"
        }
      ]
    }
  ]
  ```
</ResponseExample>

## Create Delivery Zone

<ParamField path="city" type="Id<'cities'>" required>
  City ID
</ParamField>

<ParamField path="deliveryFee" type="number">
  Default delivery fee
</ParamField>

<ParamField path="areas" type="Array<object>" required>
  Areas with custom fees and timing
</ParamField>

<CodeGroup>
  ```typescript TypeScript theme={null}
  const zone = await convex.mutation(api.stores.deliveryZones.createStoreDeliveryZone, {
    city: "ct123456789",
    deliveryFee: 5.00,
    deliveryTime: 30,
    deliveryTimeUnit: "minutes",
    areas: [
      {
        area: "ar123456789",
        deliveryFee: 5.00,
        deliveryTime: 25,
        deliveryTimeUnit: "minutes"
      }
    ]
  });
  ```
</CodeGroup>

## Update Delivery Zone

<ParamField path="deliveryZoneId" type="Id<'storeDeliveryZones'>" required>
  Zone ID to update
</ParamField>

<CodeGroup>
  ```typescript TypeScript theme={null}
  await convex.mutation(api.stores.deliveryZones.updateStoreDeliveryZone, {
    deliveryZoneId: "dz123456789",
    city: "ct123456789",
    deliveryFee: 6.00,
    areas: [/* updated areas */]
  });
  ```
</CodeGroup>

## Delete Delivery Zone

<ParamField path="deliveryZoneId" type="Id<'storeDeliveryZones'>" required>
  Zone ID to delete
</ParamField>

<CodeGroup>
  ```typescript TypeScript theme={null}
  await convex.mutation(api.stores.deliveryZones.deleteStoreDeliveryZone, {
    deliveryZoneId: "dz123456789"
  });
  ```
</CodeGroup>

<Note>
  Delivery zones determine where stores can deliver and at what cost. Configure these carefully to optimize delivery operations.
</Note>
