# Promise Dates

## Overview

parcelLab provides an API you can call to get forecasted delivery dates. This date can be used to display a delivery date promise on the product details page or at checkout. It can be shown in a format you want on your website so customers can see when a product should arrive before buying it.

{% hint style="info" %}
For more information on the scope and requirements of this feature, please contact your parcelLab representative.
{% endhint %}

## Get Promise Date

Details of how the `v2/prediction` endpoint can be used to generate a forecasted delivery date in the parcelLab system are described below.

<details>

<summary><mark style="color:blue;">GET</mark> Promise Date</summary>

You can retrieve the estimated delivery date of an order with the `v2/prediction` endpoint.

The details of the Get Promise Date API are described in the following section.

**API Details**

<mark style="color:blue;">`GET`</mark> `https://api.parcellab.com/v2/prediction`

**Query Parameters**

| Name                                          | Type          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| --------------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| user<mark style="color:red;">\*</mark>        | string        | parcelLab user ID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| destination<mark style="color:red;">\*</mark> | string        | <p>The destination country of the delivery.</p><p>Can be any of the following formats:</p><ul><li>\<country> – any country as a <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3">ISO 3166-1 alpha-3</a> code (for example: <code>USA</code>, <code>GBR</code>, <code>DEU</code></li><li>\<zip>\_\<country> – a zip code consisting only of letters and numbers (without spaces, dashes, or any other characters), with an underscore character and the country (for example: <code>02108\_USA</code>)</li></ul> |
| lang                                          | string        | <p>The language of the recipient as a</p><p><a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1</a> code for displaying localized representations of date predictions. Defaults to English.</p>                                                                                                                                                                                                                                                                                                     |
| courier                                       | string        | The logistics courier to be used. Defaults to returning all configured couriers.                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| courierServiceLevel                           | string        | The courier service level mapped in your Promise configuration (for example: express delivery). Defaults to returning all courier service levels.                                                                                                                                                                                                                                                                                                                                                                         |
| warehouse                                     | string        | The warehouse the delivery shipped from (input field: key). Defaults to the default warehouse for the destination.                                                                                                                                                                                                                                                                                                                                                                                                        |
| agent                                         | string        | The source of the request (for example: product-page, checkout), which can be used for reporting purposes but has no other impact on the prediction.                                                                                                                                                                                                                                                                                                                                                                      |
| dispatchNow                                   | boolean       | Forces the forecasted delivery date to skip any warehouse calculation and generate a prediction if the parcel is shipped at the moment of the API call, if set to `true`.                                                                                                                                                                                                                                                                                                                                                 |
| \_now                                         | date and time | Locks the prediction for a specified request date as a [ISO 8601 date and time in UTC](https://en.wikipedia.org/wiki/ISO_8601) format like `2022-06-10T06:42:00Z`. Defaults now to the current time if omitted, which is required for production usage.                                                                                                                                                                                                                                                                   |

**Responses**

* 200 - delivery prediction successfully returned, the response contains applicable predictions based on the query sent

An example successful response is displayed below to show the format for retrieving estimated delivery dates.

```javascript
{
    "requestId": "abcd1234",
    "success": true, 
    "prediction": [ ... ] 
}
```

</details>

### Result Structure

The API always returns a list of applicable predictions according to the specified query. The `requestId` is for tracing and troubleshooting purposes only.

<pre class="language-json"><code class="lang-json"><strong>{ 
</strong>    "requestId": "abcd1234", 
    "success": true,
    "error": null, 
    "prediction": [ ... ] 
} 
</code></pre>

Each entry in the prediction array represents one delivery method, including a delivery prediction like the following structure:

```json
{ 
  "id": "Delivery Method ID", 
  "warehouse": "Warehouse ID", 
  "courier": "parcelLab courier code, e.g. ups", 
  "courierName": "Pretty courier name", 
  "courierAlias": "Retailer internal courier code",
  "courierServiceLevel": [ "all specified aliases for the service level" ], 
  "prediction": { 
    "min": 1, 
    "max": 2, 
    "likely": 2,
    "send_date": "2022-06-11", 
    "earliest": "2022-06-12", 
    "latest": "2022-06-13", 
    "mostLikely": "2022-06-13", 
    "earliestLocale": "Thursday, Jun 12th, 2022", 
    "latestLocale": "Friday, Jun 13th, 2022", 
    "mostLikelyLocale": "Friday, Jun 13th, 2022", 
    "cutoff": 747, 
    "cutoffLocale": "12 hours" 
  } 
} 
```

#### Delivery Prediction Details

The details included in a delivery prediction are described in the following table.

<table><thead><tr><th width="182">Key</th><th width="216.53846153846155">Type</th><th>Description</th></tr></thead><tbody><tr><td>min</td><td>Integer</td><td>The minimum number of expected courier working days until delivery.<br><strong>Note:</strong> The value for minimum and maximum can be equal.</td></tr><tr><td>max</td><td>Integer</td><td><p>The maximum number of expected courier working days until delivery.</p><p><strong>Note:</strong> The value for minimum and maximum can be equal.</p></td></tr><tr><td>likely</td><td>Integer</td><td>The most likely number of expected courier working days until delivery.</td></tr><tr><td>send_date</td><td><a href="https://www.iso.org/iso-8601-date-and-time-format.html">ISO 8601 date format</a>: YYYY-MM-DD</td><td>The date of dispatch as per warehouse configuration.</td></tr><tr><td>earliest</td><td><a href="https://www.iso.org/iso-8601-date-and-time-format.html">ISO 8601 date format</a>: YYYY-MM-DD</td><td>The earliest expected delivery date taking into consideration working days of the courier, holidays in the destination, and warehouse cut-off and handling times.</td></tr><tr><td>latest</td><td><a href="https://www.iso.org/iso-8601-date-and-time-format.html">ISO 8601 date format</a>: YYYY-MM-DD</td><td>The latest expected delivery date taking into consideration working days of the courier, holidays in the destination, and warehouse cut-off and handling times.</td></tr><tr><td>mostLikely</td><td><a href="https://www.iso.org/iso-8601-date-and-time-format.html">ISO 8601 date format</a>: YYYY-MM-DD</td><td>The most likely individual date of delivery.</td></tr><tr><td>earliestLocale</td><td>Defaults to <code>dddd, MMM DDD, YYYY</code></td><td>Localized representations of the earliest expected delivery date in the specified format.</td></tr><tr><td>latestLocale</td><td>Defaults to <code>dddd, MMM DDD, YYYY</code></td><td>Localized representations of the latest expected delivery date in the specified format.</td></tr><tr><td>mostLikelyLocale</td><td>Defaults to <code>dddd, MMM DDD, YYYY</code></td><td>Localized representations of the most likely delivery date in the specified format.</td></tr><tr><td>cutoff</td><td>Integer</td><td>The time in minutes until cut-off for the estimated delivery dates.</td></tr><tr><td>cutoffLocale</td><td>String</td><td>Localized representations of the cut-off. Can be used within a sentence like "Order within <em>[2 hours | an hour | 20 minutes]</em> to receive your order by <em>[Saturday, Mar 23rd, 2022]</em>".</td></tr></tbody></table>

### Sample Calls

The sample API calls below show different information in the request (for example: home delivery as the courier service type) for the delivery prediction.

{% tabs %}
{% tab title="Country" %}

```json
https://api.parcellab.com/v2/prediction?user=1612197&destination=DEU
{ 
    "requestId": "wLy6ThLp", 
    "success": true, 
    "prediction": [{ 
        "id": "DHL Standard", 
        "warehouse": "Europe Warehouse",  
        "courier": "dhl-germany", 
        "courierName": "DHL", 
        "courierAlias": [],
        "courierServiceLevel": ["home-delivery","pick-from-store"]  
        "prediction": { 
            "min": 1, 
            "max": 3, 
            "likely": 2,
            "send_date": "2023-11-23", 
            "earliest": "2023-11-24", 
            "latest": "2023-11-27", 
            "mostLikely": "2022-11-25",
            "earliestLocale": "Friday, Nov 24th, 2023", 
            "latestLocale": "Monday, Nov 27th, 2023", 
            "mostLikelyLocale": "Saturday, Nov 25th, 2023", 
            "cutoff": 104, 
            "cutoffLocale": "1 hour, 44 minutes"}},
        { 
         "id": "UPS Express, 
         "warehouse": "Europe Warehouse",  
         "courier": "ups", 
         "courierName": "UPS", 
         "courierAlias": [],
         "courierServiceLevel": ["home-delivery","express","overnight"]  
         "prediction": { 
             "min": 1, 
             "max": 1, 
             "likely": 1,
             "send_date": "2023-11-23", 
             "earliest": "2023-11-24", 
             "latest": "2023-11-24", 
             "mostLikely": "2023-11-24", 
             "earliestLocale": "Friday, Nov 24th, 2023", 
             "latestLocale": "Friday, Nov 24th, 2023",
             "mostLikelyLocale": "Friday, Nov 24th, 2023", 
             "cutoff": 76, 
             "cutoffLocale": "1 hour, 16 minutes"
      }
  }]
}
```

{% endtab %}

{% tab title="Country and Zip Code" %}

```json
https://api.parcellab.com/v2/prediction?user=1612197&destination=80469_DEU
{ 
    "requestId": "Zgr8YN3w", 
    "success": true, 
    "prediction": [{ 
        "id": "DHL Standard", 
        "warehouse": "Europe Warehouse",  
        "courier": "dhl-germany", 
        "courierName": "DHL", 
        "courierAlias": [],
        "courierServiceLevel": ["home-delivery","pick-from-store"]  
        "prediction": { 
            "min": 1, 
            "max": 3, 
            "likely": 2,
            "send_date": "2023-11-23",
            "earliest": "2023-11-24",
            "latest": "2023-11-27",
            "mostLikely": "2023-11-25",
            "earliestLocale": "Friday, Nov 24th, 2023",
            "latestLocale": "Monday, Nov 27th, 2023",
            "mostLikelyLocale": "Saturday, Nov 25th, 2023",
            "cutoff": 104, 
            "cutoffLocale": "1 hour, 44 minutes"}},
        { 
         "id": "UPS Express, 
         "warehouse": "Europe Warehouse",  
         "courier": "ups", 
         "courierName": "UPS", 
         "courierAlias": [],
         "courierServiceLevel": ["home-delivery","express","overnight"]  
         "prediction": { 
             "min": 1, 
             "max": 1, 
             "likely": 1,
             "send_date": "2023-11-23",
             "earliest": "2023-11-24",
             "latest": "2023-11-24",
             "mostLikely": "2022-11-24",
             "earliestLocale": "Friday, Nov 24th, 2023",
             "latestLocale": " Friday, Nov 24th, 2023",
             "mostLikelyLocale": "Friday, Nov 24th, 2023",
             "cutoff": 76, 
             "cutoffLocale": "1 hour, 16 minutes"
       }    
  }]
}
```

{% endtab %}

{% tab title="Specific Service Types" %}

```json
https://api.parcellab.com/v2/prediction?user=1612197&destination=USA&courierServiceLevel=home-delivery
{ 
    "requestId": "gxFAiZfP", 
    "success": true, 
    "prediction": [{ 
        "id": "USPS Standard", 
        "warehouse": "US East Coast Warehouse",  
        "courier": "usps", 
        "courierName": "USPS", 
        "courierAlias": [],
        "courierServiceLevel": ["home-delivery","pick-from-store"]  
        "prediction": { 
            "min": 3, 
            "max": 5, 
            "likely": 4, 
            "send_date": "2022-08-19", 
            "earliest": "2022-08-24", 
            "latest": "2022-08-26", 
            "mostLikely": "2022-08-25",
            "earliestLocale": "Wednesday, Aug 24th, 2022", 
            "latestLocale": "Friday, Aug 26th, 2022", 
            "mostLikelyLocale": "Thursday, Aug 25th, 2022", 
            "cutoff": 1236, 
            "cutoffLocale": "21 hours" 
      } 
  }]
}
```

{% endtab %}
{% endtabs %}

### Calculating Delivery Dates for Orders with Known Dispatch Date

For orders where you know the actual dispatch date, you can calculate accurate delivery dates based on when the order will ship. This is useful for scenarios where:

* An order's dispatch date is confirmed after placement
* You need to provide customers with updated delivery expectations based on actual shipment dates
* Customer service agents need to communicate accurate timelines for existing orders

**How It Works**

To calculate a delivery date for an already placed order when you know the dispatch date, use these two parameters together:

1. `_now=<date>` - set this to the known dispatch date/time in ISO 8601 UTC format (for example: `2025-07-01T16:00:00.000Z`)
2. `dispatchNow=true` - this forces the API to skip warehouse cutoff calculations and calculate the delivery date as if the parcel ships at the exact time specified in `_now`

{% hint style="warning" %}
The `_now` timestamp must be in UTC (Zulu time), not local time. Always include the `Z` suffix or `.000Z` to indicate UTC.
{% endhint %}

{% hint style="info" %}
When using `dispatchNow=true` with a specific `_now` value for already placed orders, the `cutoff` will be 0 as you're bypassing warehouse calculations and calculating delivery based on the known dispatch time.
{% endhint %}

### Testing Your Promise Configuration

To preview saved but unpublished changes to your Promise configuration in a staging environment:

1. Integrate the Promise API call to your staging environment.
2. Add the query parameter `&draft=true` to your Promise API call.

This will generate a promise date based on your unpublished Promise configuration, that can be used to review the effect of any configuration updates on the frontend of your staging environment.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.parcellab.com/docs/developers/v2/promise/promise-dates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
