---
schema_version: "1"
id: 724a1389a2200dcdcfaf45efcff3f9857d832fc172af4948add02bc9f61dc9c0
title: Configure Delivery Estimation for a B2C Store
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/commerce/264-0-0/om_del_est_config_for_b2c_store.md
canonical_url: https://help.salesforce.com/s/articleView?id=commerce.om_del_est_config_for_b2c_store.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 1a230225384924728da52fae29210f9ade5dd5715ce797e92c75a4ef9314e9c3
description: Connect the Commerce Delivery Service to your B2C store and implement the delivery estimation service for checkout. Use this section as a guideline only. Your configuration may differ.
products:
  - Commerce
  - Salesforce Order Management
release: "264"
---
# Configure Delivery Estimation for a B2C Store

Connect the Commerce Delivery Service to your B2C store and implement the delivery estimation service for checkout. Use this section as a guideline only. Your configuration may differ.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=commerce.om_editions.htm&amp;language=en_US" target="_blank">View supported editions</a>.</td></tr></tbody></table>

Before beginning this task, make sure the [Order Fulfillment Setup section](https://help.salesforce.com/s/articleView?id=commerce.om_enable_order_management_setup.htm&release=264.0.0&type=5 "The Order Fulfillment Setup section is the landing page for all components of Commerce Delivery Service (CDS).") is enabled.

1. Add a role, instance, and scope.
    1. In Commerce Account Manager, select **Account Manager | API Client**.
    2. Add the Salesforce Commerce API role and its associated instances.
    3. Add the sfcc.commercedeliveryservice.shopper allowed scope.
2. In Business Manager, create custom product line attributes.
    1. Log in to Business Manager with Administrative privileges.
    2. Go to **Administration | Site Development | System Object Types**, and select **ProductLineItem**.
    3. On the Attribute Definitions tab, click **New** and create these attributes.
        
         
        | **Attributes** | **Value** |
        | --- | --- |
        | EarliestEstimated​DeliveryDateTime | Type Date+Time |
        | LatestEstimated​DeliveryDateTime | Type Date+Time |
        | EstimatedDelivery​Reference | Type String |
3. (Optional) Add the product line attributes to a group.
    1. On the Attribute Grouping tab, add a group named Commerce Delivery Service.
    2. Edit the group, and add the attributes that you created.
        
         
        | **Attributes** | **Value** |
        | --- | --- |
        | EarliestEstimated​DeliveryDateTime | Type Date+Time |
        | LatestEstimated​DeliveryDateTime | Type Date+Time |
        | EstimatedDelivery​Reference | Type String |
4. (Optional) Create custom site attributes.
    1. In Business Manager, select **Administration | Site Development | System Object Types | SitePreferences**.
    2. On the Attribute Definitions tab, click **New** and create these attributes.
        
        <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
                <colgroup>
                  <col style="width:50%">
                  <col style="width:50%">
                </colgroup>
                <thead class="slds-text-title_caps ">
                  <tr class="">
                    <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d9075e314">
                      <strong class="uicontrol">Attributes</strong>
                    </th>
                    <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d9075e320">
                      <strong class="uicontrol">Value</strong>
                    </th>
                  </tr>
                </thead>
                <tbody>
                  <tr class="">
                    <td data-label="Attributes" class="slds-cell-wrap" style="vertical-align:top;" headers="d9075e314 ">accountManager</td>

                    <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d9075e320 ">
                      <p>Value Type: Enum of Strings</p>
                      <p>Value =
                        account.demandware.com</p>
                      <p style="margin-bottom:0;">Display Value =
                        Prod</p>
                    </td>

                  </tr>
                  <tr class="">
                    <td data-label="Attributes" class="slds-cell-wrap" style="vertical-align:top;" headers="d9075e314 ">cdsClientId</td>

                    <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d9075e320 ">
                      <p>Value Type: String</p>
                      <p style="margin-bottom:0;">The UUID in Account
                        Manager</p>
                    </td>

                  </tr>
                  <tr class="">
                    <td data-label="Attributes" class="slds-cell-wrap" style="vertical-align:top;" headers="d9075e314 ">cdsPassword</td>

                    <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d9075e320 ">
                      <p>Value Type: String</p>
                      <p style="margin-bottom:0;">Password associated with
                        your UUID/ClientID</p>
                    </td>

                  </tr>
                  <tr class="">
                    <td data-label="Attributes" class="slds-cell-wrap" style="vertical-align:top;" headers="d9075e314 ">realmInstanceId</td>

                    <td data-label="Value" class="slds-cell-wrap" style="vertical-align:top;" headers="d9075e320 ">
                      <p>Value Type: String</p>
                      <p style="margin-bottom:0;">Realm_instance
                        identifier</p>
                    </td>

                  </tr>
                </tbody>
              </table>
5. (Optional) Set custom site preferences.
    1. In Business Manager, select **Merchant Tools | Site Preferences | Custom Preferences**.
    2. For Commerce Delivery Service, click **ID Link**.
    3. Enter these properties, and then click **Save**.
        
         
        | **Attributes** | **Value** |
        | --- | --- |
        | cdsClientId | Find in Account Manager. |
        | cdsPassword | Password associated with the UUID/ClientID. |
        | RealmInstanceId | To find, go to **Administration | Global Preferences | Salesforce Order Management Integration Administration**. |
6. (Optional) Call Account Manager to receive the correct bearer token. Use the token in the request that calls the Commerce Delivery Service.
    
    ```
    function callAccountManager() {
        var sitePrefs : SitePreferences = dw.system.Site.getCurrent().getPreferences();
        var realmInstanceId : String = sitePrefs.getCustom()["realmInstanceId"];
        var clientId : String = sitePrefs.getCustom()["cdsClientId"];
        var password : String = sitePrefs.getCustom()["cdsPassword"];
        var url : String = sitePrefs.getCustom()["accountManager"];
        var wholeUrl : String = 'https://'+ url + '/dw/oauth2/access_token?grant_type=client_credentials&​scope=SALESFORCE_COMMERCE_API%3A'+realmInstanceId+'%20​sfcc.commercedeliveryservice.shopper';
        var httpClient : HTTPClient = new HTTPClient();
        var message : String;
    
        httpClient.open('POST', wholeUrl,''+ clientId + '',''+ password +'');
        httpClient.setRequestHeader('Accept','application/json');
        httpClient.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        httpClient.setTimeout(3000);
        httpClient.send();
        if (httpClient.statusCode == 200)
        {
             message = httpClient.text;
        }
        else
        {
            // error handling
            message="An error occurred with status code "+httpClient.text;
        }
        
        return JSON.parse(message).access_token;
    }
    ```
7. Create a request to use in the body for the call to the CDS Service.
    1. Create a request function.
        
        ```
        function createCdsRequest(applicableShippingMethods, products) {
            var siteName: String = dw.system.Site.getCurrent().name;
            let jsonObj = {};
        
            jsonObj.deliveryEstimationSetupName = dw.system.Site.getCurrent().name;
            jsonObj.shippingCarrier.methods = [];
            jsonObj.products = [];
            jsonObj.deliveryAddress = {};
        
            for (var i = 0; i < products.length; i++) {
                jsonObj.products.push({});
                jsonObj.products[i]['stockKeepingUnit'] = products[i].productID;
                jsonObj.products[i]['quantity'] = products[i].quantityValue;
            }
        
            jsonObj.deliveryAddress.country = request.httpParameterMap.countryCode.stringValue;
            jsonObj.deliveryAddress.state = request.httpParameterMap.stateCode.stringValue;
            jsonObj.deliveryAddress.postalCode = request.httpParameterMap.postalCode.stringValue;
            jsonObj.deliveryAddress.city = request.httpParameterMap.city.stringValue;
        
            for (i = 0; i < applicableShippingMethods.length; i++) {
                jsonObj.shippingCarrier.methods.push({});
                jsonObj.shippingCarrier.methods[i]['name'] = applicableShippingMethods[i].ID;
            }
        
            return jsonObj;
        }
        ```
    2. Call your request function.
        
        ```
        applicableShippingMethods = cart.getApplicableShippingMethods(address);
        products = cart.getProductLineItems();
        ...
        createCdsRequest(applicableShippingMethods, products)
        ```
8. (Optional) Use the dates and reference numbers in the storefront. Call the CDS Service to pull the response and use the dates and reference numbers in the storefront.
    
    ```
    function callCdsService(bearer, request) {
        var httpClient: HTTPClient = new HTTPClient();
        var message: String;
        var sitePrefs: SitePreferences = dw.system.Site.getCurrent().getPreferences();
        var realmInstanceId: String = sitePrefs.getCustom()["realmInstanceId"];
    
    
        httpClient.open('POST', 'https://api.salesforce.com/commerce/delivery/v1/estimate/delivery-date');
        httpClient.setRequestHeader('Authorization', 'Bearer ' + bearer + '');
        httpClient.setRequestHeader('Accept', '*/*');
        httpClient.setRequestHeader('Content-Type', 'application/json');
        httpClient.setRequestHeader('Accept-Encoding', 'gzip, deflate, br');
        httpClient.setRequestHeader('Connection', 'keep-alive');
        httpClient.setRequestHeader('Correlation-ID', '12345');
        httpClient.setRequestHeader('SALESFORCE_COMMERCE_API', '' + realmInstanceId + '');
        httpClient.setRequestHeader('x-salesforce-region', 'us-east-2');
        httpClient.setTimeout(5000);
        httpClient.setBody(payload);
        httpClient.send(request);
        if (httpClient.statusCode == 200) {
            message = httpClient.text;
        } else {
            // error handling
            message = "An error occurred with status code " + httpClient.errorText;
        }
    
        return message;
    }
    ```
    
    **Sample request**
    
    These fields are mandatory: methods, name, products, stockKeepingUnit.
    
    ```
    {
     “deliveryEstimationSetupName”: “{externalName}”,
     "shippingCarrier": {
      "name": "FEDEX",
      "methods": [
       {
        "name": "GROUND"
       }
      ]
     },
     "products": [
      {
       "stockKeepingUnit": "PROD123",
       "quantity": 3,
      }
     ],
     "deliveryAddress": {
      "country": "USA",
      "state": "WA",
      "city": "Seattle",
      "postalCode": "98108",
      "latitude": 25.191274,
      "longitude": -80.13145
     },
     "excludedLocations": [
      "US-EAST",
      "US-WEST"
     ]
    }
    ```
    
    **Sample response**
    
    ```
    {
        "estimatedDeliveryReference": "e40cf167-dbd7-11ee-ae25-f1239303df20",
        "deliveryEstimates": [{
                "shippingCarrierMethod": "Ground",
                "productDeliverEstimations": [{
                        "stockKeepingUnit": "1",
                        "quantity": 2,
                        "routingCalculationType": "NONE",
                        "estimatedShipDate": {
                            "type": "Default",
                            "min": "2024-03-08T13:00:00",
                            "max": "2024-03-08T13:00:00"
                        },
                        "estimatedDeliveryDate": {
                            "type": "Default",
                            "min": "2024-03-14T13:00:00",
                            "max": "2024-03-17T13:00:00"
                        }
                    },
                    {
                        "stockKeepingUnit": "2",
                        "quantity": 3,
                        "routingCalculationType": "NONE",
                        "estimatedShipDate": {
                            "type": "Default",
                            "min": "2024-03-08T13:00:00",
                            "max": "2024-03-08T13:00:00"
                        },
                        "estimatedDeliveryDate": {
                            "type": "Default",
                            "min": "2024-03-14T13:00:00",
                            "max": "2024-03-17T13:00:00"
                        }
                    }
                ]
            },
            {
                "shippingCarrierMethod": "2-Day",
                "productDeliverEstimations": [{
                        "stockKeepingUnit": "1",
                        "quantity": 2,
                        "routingCalculationType": "NONE",
                        "estimatedShipDate": {
                            "type": "Default",
                            "min": "2024-03-08T13:00:00",
                            "max": "2024-03-08T13:00:00"
                        },
                        "estimatedDeliveryDate": {
                            "type": "Default",
                            "min": "2024-03-10T13:00:00",
                            "max": "2024-03-12T13:00:00"
                        }
                    },
                    {
                        "stockKeepingUnit": "2",
                        "quantity": 3,
                        "routingCalculationType": "NONE",
                        "estimatedShipDate": {
                            "type": "Default",
                            "min": "2024-03-08T13:00:00",
                            "max": "2024-03-08T13:00:00"
                        },
                        "estimatedDeliveryDate": {
                            "type": "Default",
                            "min": "2024-03-10T13:00:00",
                            "max": "2024-03-12T13:00:00"
                        }
                    }
                ]
            },
            {
                "shippingCarrierMethod": "Overnight",
                "productDeliverEstimations": [{
                        "stockKeepingUnit": "1",
                        "quantity": 2,
                        "routingCalculationType": "NONE",
                        "estimatedShipDate": {
                            "type": "Default",
                            "min": "2024-03-08T13:00:00",
                            "max": "2024-03-08T13:00:00"
                        },
                        "estimatedDeliveryDate": {
                            "type": "Default",
                            "min": "2024-03-08T13:00:00",
                            "max": "2024-03-09T13:00:00"
                        }
                    },
                    {
                        "stockKeepingUnit": "2",
                        "quantity": 3,
                        "routingCalculationType": "NONE",
                        "estimatedShipDate": {
                            "type": "Default",
                            "min": "2024-03-08T13:00:00",
                            "max": "2024-03-08T13:00:00"
                        },
                        "estimatedDeliveryDate": {
                            "type": "Default",
                            "min": "2024-03-08T13:00:00",
                            "max": "2024-03-09T13:00:00"
                        }
                    }
                ]
            }
        ]
    }
    ```
    
    **Sample parse through response**
    
    ```
    // Create two maps, min and max
    var maxDate = new Map();
    var minDate = new Map();
    ...
    // Apply response values to display when seeing all Shipping Methods in the order
    for (i = 0; i < JSON.parse(response).deliveryEstimates.length; i++) {
        if (JSON.parse(response).deliveryEstimates[i].shippingCarrierMethod == applicableShippingMethods[i].ID) {
            minDate.set(JSON.parse(response).deliveryEstimates[i].shippingCarrierMethod, new Date(Date.parse(JSON.parse(response).deliveryEstimates[i].productDeliverEstimations[0].estimatedDeliveryDate.min)).toLocaleDateString());
            maxDate.set(JSON.parse(response).deliveryEstimates[i].shippingCarrierMethod, new Date(Date.parse(JSON.parse(response).deliveryEstimates[i].productDeliverEstimations[0].estimatedDeliveryDate.max)).toLocaleDateString());
        }
    }
    ...
    // Apply response values to each Product Line Item (OrderItem) for (var i = 0; i < JSON.parse(response).deliveryEstimates.length; i++) {
    if (JSON.parse(response).deliveryEstimates[i].shippingCarrierMethod == cart.getDefaultShipment().getShippingMethod().ID) {
        for (var c = 0; c < cart.object.productLineItems.length; c++) {
            cart.object.productLineItems[c].custom.EstimatedDeliveryReference = JSON.parse(response).estimatedDeliveryReference;
            cart.object.productLineItems[c].custom.EarliestEstimatedDeliveryDateTime = new Date(Date.parse(JSON.parse(response).deliveryEstimates[i].productDeliverEstimations[0].estimatedDeliveryDate.min));
            cart.object.productLineItems[c].custom.LatestEstimatedDeliveryDateTime = new Date(Date.parse(JSON.parse(response).deliveryEstimates[i].productDeliverEstimations[0].estimatedDeliveryDate.max));
        }
    }
    }
    ```
9. (Optional) Update any .isml pages to use the values returned in the response from the Commerce Delivery Service.
    
    In this example, to display the dates, minimum and maximum dates are placed in a new Map() and then displayed based on the shipping method.
    
    ```javascript
    <isif condition = "${!empty(shippingMethod.description)}" >
         <div class = "form-caption" > Delivery Estimation: $ {
                            pdict.MinDate.get(shippingMethod.ID)} - $ {
                            pdict.MaxDate.get(shippingMethod.ID)} 
         < /div> 
    </isif>
    ```

Next step: [Enable and Sync a Delivery Estimation](https://help.salesforce.com/s/articleView?id=commerce.om_del_est_sync_to_cds.htm&release=264.0.0&type=5 "After you’ve configured estimations and shipping, and you’ve connected Commerce Delivery Services to B2C Commerce as necessary, enable your delivery estimation.")

#### See Also

- [Delivery Estimations for Order Management Overview](https://help.salesforce.com/s/articleView?id=commerce.om_del_est_overview.htm&release=264.0.0&type=5 "Provide customers with accurate delivery times by showing delivery dates on your store’s product detail and checkout pages.")