# Selecting a shipping method

## Problem

You have a pending order and you want to give your customer the possibility to select a shipping method for each of the order shipments, based on its cost and delivery lead time.

![A sample shipping method selection](https://2610849379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lk-ezuDClaMavTqnRi0%2Fuploads%2FBaWYKbKhJU2WJ4ty14rw%2Fselect-shipping-method-cover.jpg?alt=media\&token=7f62e613-b71e-47cb-babb-5cbd1f92d422)

## Solution

Within Commerce Layer, an order can have many shipments and each shipment must have a valid shipping method before the order can be placed. To let the customer select a shipping method, first you need to get the list of available shipping methods for the order shipments and display them to the customer along with their delivery lead times. Then you can associate the selected shipping method with the shipment and eventually display its delivery lead time. To do that:

1. Send a `GET` request to the `/api/orders/:id/shipments` endpoint, including the associated `available_shipping_methods` and `stock_location`.
2. Send a `GET` request to the `/api/orders/delivery_lead_times`, including the associated `shipping_method` and `stock_location`, and add some front-end logic to determine which of the returned delivery lead times is associated with a stock location that matches the one associated with the shipment.
3. Send a `PATCH` request to the `/api/shipments/:id` endpoint, setting its `shipping_method` relationship.
4. Send a `GET` request to the `/api/shipments/:id endpoint`, including the associated `shipping_method` and `delivery_lead_time`.

{% hint style="info" %}
Including the stock location in the API calls above is necessary to be able to display the correct delivery lead time, especially if the order is split into many shipments.
{% endhint %}

### Example

#### 1. Get the available shipping methods

{% tabs %}
{% tab title="Request" %}
The following request retrieves the list of available shipping methods associated with the shipments of the order identified by the "NgojhKoyYN" ID:

```bash
curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/orders/NgojhKoyYN/shipments?include=available_shipping_methods,stock_location' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Accept: application/vnd.api+json'
```

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the list of shipment objects and the associated available shipping methods and stock locations:

<pre class="language-json"><code class="lang-json">{
  "data": [
    {
      "id": "kPzgnCjdQy",
      "type": "shipments",
      "links": {
        "self": "https://yourdomain.commercelayer.io/api/shipments/kPzgnCjdQy"
      },
      "attributes": {
        "number": "1234/S/001",
        "status": "upcoming",
        "currency_code": "EUR",
        "cost_amount_cents": 0,
        "cost_amount_float": 0.0,
        "formatted_cost_amount": "$0.00",
        "skus_count": 4,
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "metadata": {}
      },
      "relationships": {
        "order": {
          "links": {...}
        },
        "shipping_category": {
          "links": {...}
        },
        "stock_location": {
          "links": {...}
          "data": {
            "type": "stock_locations",
            "id": "DMzAouwyXk"
          }
        },
        "origin_address": {
          "links": {...}
        },
        "shipping_address": {
          "links": {...}
        },
        "shipping_method": {
          "links": {...}
        },
        "delivery_lead_time": {
          "links": {...}
        },
        "shipment_line_items": {
          "links": {...}
        },
        "stock_transfers": {
          "links": {...}
        },
        "available_shipping_methods": {
          "links": {...},
          "data": [
            {
              "type": "shipping_methods",
              "id": "WErDzFLeQN"
            },
            {
              "type": "shipping_methods",
              "id": "DEqjzFMykO"
            }
          ]
        },
        "carrier_accounts": {
          "links": {...}
        },
        "parcels": {
          "links": {...}
        },
        "attachments": {...}
        }
      },
      "meta": {
          "mode": "test"
      }
    }
  ],
<strong>  "included": [
</strong>    {
      "id": "DMzAouwyXk",
      "type": "stock_locations",
      "links": {...},
      "attributes": {
        "number": 1234,
<strong>        "name": "Primary Warehouse",
</strong>        "label_format": "PDF",
        "suppress_etd": null,
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "address": {
            "links": {...}
        },
        "inventory_stock_locations": {
            "links": {...}
        },
        "inventory_return_locations": {
            "links": {...}
        },
        "stock_items": {
            "links": {...}
        },
        "stock_transfers": {
            "links": {...}
        },
        "attachments": {
            "links": {...}
        }
      },
      "meta": {
          "mode": "test"
      }
    },
    {
      "id": "WErDzFLeQN",
      "type": "shipping_methods",
      "links": {
          "self": "https://yourdomain.commercelayer.io/api/shipping_methods/WErDzFLeQN"
      },
      "attributes": {
<strong>        "name": "Standard Shipping",
</strong>        "disabled_at": null,
        "currency_code": "EUR",
        "price_amount_cents": 700,
        "price_amount_float": 7.0,
        "formatted_price_amount": "€7,00",
        "free_over_amount_cents": 9900,
        "free_over_amount_float": 99.0,
        "formatted_free_over_amount": "€99,00",
        "price_amount_for_shipment_cents": 0,
        "price_amount_for_shipment_float": 0.0,
        "formatted_price_amount_for_shipment": "€0,00",
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "metadata": {}
      },
      "relationships": {
        "market": {
          "links": {...}
        },
        "shipping_zone": {
          "links": {...}
        },
        "shipping_category": {
          "links": {...}
        },
        "delivery_lead_time_for_shipment": {
          "links": {...}
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "id": "DEqjzFMykO",
      "type": "shipping_methods",
      "links": {
        "self": "https://yourdomain.commercelayer.io/api/shipping_methods/DEqjzFMykO"
      },
      "attributes": {
<strong>        "name": "Express Delivery",
</strong>        "disabled_at": null,
        "currency_code": "EUR",
        "price_amount_cents": 1200,
        "price_amount_float": 12.0,
        "formatted_price_amount": "€10,00",
        "free_over_amount_cents": null,
        "free_over_amount_float": null,
        "formatted_free_over_amount": null,
        "price_amount_for_shipment_cents": 1200,
        "price_amount_for_shipment_float": 12.0,
        "formatted_price_amount_for_shipment": "€12,00",
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "metadata": {}
      },
      "relationships": {
        "market": {
          "links": {..}
        },
        "shipping_zone": {
          "links": {...}
        },
        "shipping_category": {
          "links": {...}
        },
        "delivery_lead_time_for_shipment": {
          "links": {...}
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    }
  ],
  "meta": {
    "record_count": 1,
    "page_count": 1
  },
  "links": {
      "first": "https://yourdomain.commercelayer.io/api/orders/NgojhKoyYN/shipments?include=available_shipping_methods,stock_location&#x26;page[number]=1&#x26;page[size]=10",
      "last": "https://yourdomain.commercelayer.io/api/orders/NgojhKoyYN/shipments?include=available_shipping_methods,stock_location&#x26;page[number]=1&#x26;page[size]=10"
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

#### 2. Displaying the available shipping methods delivery lead times

{% tabs %}
{% tab title="Request" %}
The following request retrieves the list of the delivery lead times for the market in scope:

```bash
curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/delivery_lead_times?include=shipping_method,stock_location' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Accept: application/vnd.api+json'
```

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the list of delivery lead time objects and the associated shipping methods and stock locations:

<pre class="language-bash"><code class="lang-bash">{
  "data": [
    {
      "id": "nOZwqFYXQB",
      "type": "delivery_lead_times",
      "links": {...},
      "attributes": {
        "min_hours": 72,
        "max_hours": 120,
        "min_days": 3,
        "max_days": 5,
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "stock_location": {
          "links": {...},
          "data": {
            "type": "stock_locations",
            "id": "DMzAouwyXk"
          }
        },
        "shipping_method": {
          "links": {...},
          "data": {
            "type": "shipping_methods",
            "id": "WErDzFLeQN"
          }
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "id": "AxwloFjQbp",
      "type": "delivery_lead_times",
      "links": {...},
      "attributes": {
<strong>        "min_hours": 48,
</strong><strong>        "max_hours": 72,
</strong><strong>        "min_days": 2,
</strong><strong>        "max_days": 3,
</strong>        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "stock_location": {
          "links": {...},
          "data": {
            "type": "stock_locations",
            "id": "DMzAouwyXk"
          }
        },
        "shipping_method": {
          "links": {...},
          "data": {
            "type": "shipping_methods",
            "id": "DEqjzFMykO"
          }
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "id": "vxRoAFeymp",
      "type": "delivery_lead_times",
      "links": {...},
      "attributes": {
<strong>        "min_hours": 96,
</strong><strong>        "max_hours": 144,
</strong><strong>        "mdin_days": 4,
</strong><strong>        "max_days": 6,
</strong>        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "stock_location": {
          "links": {...},
          "data": {
            "type": "stock_locations",
            "id": "enbqQuXVwM"
          }
        },
        "shipping_method": {
          "links": {...},
          "data": {
            "type": "shipping_methods",
            "id": "WErDzFLeQN"
          }
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "id": "zBdZGFADkp",
      "type": "delivery_lead_times",
      "links": {...},
      "attributes": {
<strong>        "min_hours": 72,
</strong><strong>        "max_hours": 96,
</strong><strong>        "min_days": 3,
</strong><strong>        "max_days": 4,
</strong>        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "stock_location": {
          "links": {...},
          "data": {
            "type": "stock_locations",
            "id": "enbqQuXVwM"
          }
        },
        "shipping_method": {
          "links": {...},
          "data": {
            "type": "shipping_methods",
            "id": "DEqjzFMykO"
          }
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    }
  ],
  "included": [
    {
      "id": "DMzAouwyXk",
      "type": "stock_locations",
      "links": {...},
      "attributes": {
        "number": 1234,
<strong>        "name": "Primary Warehouse",
</strong>        "label_format": "PDF",
        "suppress_etd": null,
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "address": {
          "links": {...}
        },
        "inventory_stock_locations": {
          "links": {...}
        },
        "inventory_return_locations": {
          "links": {...}
        },
        "stock_items": {
          "links": {...}
        },
        "stock_transfers": {
          "links": {...}
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "id": "enbqQuXVwM",
      "type": "stock_locations",
      "links": {...},
      "attributes": {
        "number": 2345,
<strong>        "name": "Backorder Warehouse",
</strong>        "label_format": "PDF",
        "suppress_etd": null,
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "address": {
          "links": {...}
        },
        "inventory_stock_locations": {
          "links": {...}
        },
        "inventory_return_locations": {
          "links": {...}
        },
        "stock_items": {
          "links": {...}
        },
        "stock_transfers": {
          "links": {...}
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "id": "WErDzFLeQN",
      "type": "shipping_methods",
      "links": {...},
      "attributes": {
<strong>        "name": "Standard Shipping",
</strong>        "disabled_at": null,
        "currency_code": "EUR",
        "price_amount_cents": 700,
        "price_amount_float": 7.0,
        "formatted_price_amount": "€7,00",
        "free_over_amount_cents": 9900,
        "free_over_amount_float": 99.0,
        "formatted_free_over_amount": "€99,00",
        "price_amount_for_shipment_cents": 700,
        "price_amount_for_shipment_float": 7.0,
        "formatted_price_amount_for_shipment": "€7,00",
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "market": {
          "links": {...}
        },
        "shipping_zone": {
          "links": {...}
        },
        "shipping_category": {
          "links": {...}
        },
        "delivery_lead_time_for_shipment": {
          "links": {...}
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "id": "DEqjzFMykO",
      "type": "shipping_methods",
      "links": {...},
      "attributes": {
<strong>        "name": "Express Delivery",
</strong>        "disabled_at": null,
        "currency_code": "EUR",
        "price_amount_cents": 1200,
        "price_amount_float": 12.0,
        "formatted_price_amount": "€12,00",
        "free_over_amount_cents": null,
        "free_over_amount_float": null,
        "formatted_free_over_amount": null,
        "price_amount_for_shipment_cents": 1200,
        "price_amount_for_shipment_float": 12.0,
        "formatted_price_amount_for_shipment": "€12,00",
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "market": {
          "links": {...}
        },
        "shipping_zone": {
          "links": {...}
        },
        "shipping_category": {
          "links": {...}
        },
        "delivery_lead_time_for_shipment": {
          "links": {...}
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    }
  ],
  "meta": {
    "record_count": 4,
    "page_count": 1
  },
  "links": {
    "first": "https://yourdomain.commercelayer.io/api/delivery_lead_times?include=shipping_method,stock_location&#x26;page[number]=1&#x26;page[size]=10",
    "last": "https://yourdomain.commercelayer.io/api/delivery_lead_times?include=shipping_method,stock_location&#x26;page[number]=1&#x26;page[size]=10"
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

For performance reasons and to minimize the number of calls to the API, at this point you need to add the necessary logic to determine which of the returned delivery lead times has to be displayed for each shipping method **on the front-end**. Basically, it's all about — for each one of the available shipping methods associated with each shipment — filtering the returned delivery lead times to find which one is associated with a stock location that matches the stock location associated with the shipment.

The image below shows which specific attribute of the shipping method and delivery lead time object has to be displayed.

![A sample available shipping methods delivery lead times mapping](https://2610849379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lk-ezuDClaMavTqnRi0%2Fuploads%2F5WXfJLbZCz7yFiDUP6GY%2Fselect-shipping-method-mapping.jpg?alt=media\&token=2b76ad0b-17bb-4eb3-b241-0d125e1f322e)

{% hint style="warning" %}
For performance reasons, in the response of both the above calls ([1.](#1.-get-the-available-shipping-methods) and [2.](#2.-displaying-the-available-shipping-methods-delivery-lead-times)) the price of the shipping methods whose cost is supposed to be provided [by an external service](https://app.gitbook.com/s/-LgByaSP8eKjad-MIuHE/external-resources/external-shipping-costs) (if any) is not updated with the value calculated externally which is fetched only when the shipping method is [selected](#3.-select-a-shipping-method).
{% endhint %}

#### 3. Select a shipping method

{% tabs %}
{% tab title="Request" %}
The following request associates the selected shipping method (identified by the "DEqjzFMykO" ID) with the shipment identified by the "kPzgnCjdQy" ID:

<pre class="language-bash"><code class="lang-bash">curl -g -X PATCH \
  'https://yourdomain.commercelayer.io/api/shipments/kPzgnCjdQy' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
    "data": {
      "type": "shipments",
      "id": "kPzgnCjdQy",
      "relationships": {
<strong>        "shipping_method": {
</strong>          "data": {
            "type": "shipping_methods",
            "id": "DEqjzFMykO"
          }
        }
      }
    }
  }'
</code></pre>

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the updated shipment object:

<pre class="language-json"><code class="lang-json">{
  "data": {
    "id": "kPzgnCjdQy",
    "type": "shipments",
    "links": {
        "self": "https://yourdomain.commercelayer.io/api/shipments/kPzgnCjdQy"
    },
    "attributes": {
      "number": "1234/S/001",
      "status": "upcoming",
      "currency_code": "EUR",
      "cost_amount_cents": 0,
      "cost_amount_float": 0.0,
      "formatted_cost_amount": "$0.00",
      "skus_count": 4,
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": null,
      "metadata": {}
    },
    "relationships": {
      "order": {
        "links": {...}
      },
      "shipping_category": {
        "links": {...}
      },
      "stock_location": {
        "links": {...}
      },
      "shipping_address": {
        "links": {...}
      },
<strong>      "shipping_method": {
</strong>        "links": {...}
      },
      "shipment_line_items": {
        "links": {...}
      },
      "available_shipping_methods": {
        "links": {...}
      },
      "parcels": {
        "links": {...}
      },
      "attachments": {
        "links": {...}
      }
    },
    "meta": {
      "mode": "test"
    }
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

#### 4. Displaying the selected shipping method delivery lead time

{% tabs %}
{% tab title="Request" %}
The following request retrieves the delivery lead time associated with the shipment identified by the "kPzgnCjdQy" ID:

```bash
curl -g -X GET \ 
  'https://yourdomain.commercelayer.io/api/shipments/kPzgnCjdQy?include=shipping_method,delivery_lead_time' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Accept: application/vnd.api+json'
```

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the selected shipment object, together with the associated shipping method and delivery lead time:

<pre class="language-json"><code class="lang-json">{
  "data": {
    "id": "kPzgnCjdQy",
    "type": "shipments",
    "links": {...},
    "attributes": {
      "number": "1234/S/001",
      "status": "upcoming",
      "currency_code": "EUR",
      "cost_amount_cents": 0,
      "cost_amount_float": 0.0,
      "formatted_cost_amount": "$0.00",
      "skus_count": 5,
      "rates": [],
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": null,
      "reference_origin": null,
      "metadata": {}
    },
    "relationships": {
      "order": {
        "links": {...}
      },
      "shipping_category": {
        "links": {...}
      },
      "stock_location": {
        "links": {...}
      },
      "origin_address": {
        "links": {...}
      },
      "shipping_address": {
        "links": {...}
      },
      "shipping_method": {
        "links": {...},
        "data": {
          "type": "shipping_methods",
          "id": "DEqjzFMykO"
        }
      },
      "delivery_lead_time": {
        "links": {...},
        "data": {
          "type": "delivery_lead_times",
          "id": "AxwloFjQbp"
        }
      },
      "shipment_line_items": {
        "links": {...}
      },
      "stock_transfers": {
        "links": {...}
      },
      "available_shipping_methods": {
        "links": {...}
      },
      "carrier_accounts": {
        "links": {...}
      },
      "parcels": {
        "links": {...}
      },
      "attachments": {
        "links": {...}
      }
    },
    "meta": {
      "mode": "test"
    }
  },
  "included": [
    {
      "id": "DEqjzFMykO",
      "type": "shipping_methods",
      "links": {...},
      "attributes": {
<strong>        "name": "Express Delivery",
</strong>        "disabled_at": null,
        "currency_code": "EUR",
        "price_amount_cents": 1200,
        "price_amount_float": 12.0,
        "formatted_price_amount": "€7,00",
        "free_over_amount_cents": null,
        "free_over_amount_float": null,
        "formatted_free_over_amount": null,
        "price_amount_for_shipment_cents": 1200,
        "price_amount_for_shipment_float": 12.0,
        "formatted_price_amount_for_shipment": "€12,00",
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "market": {
          "links": {...}
        },
        "shipping_zone": {
          "links": {...}
        },
        "shipping_category": {
          "links": {...}
        },
        "delivery_lead_time_for_shipment": {
          "links": {...}
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "id": "AxwloFjQbp",
      "type": "delivery_lead_times",
      "links": {...},
      "attributes": {
<strong>        "min_hours": 48,
</strong><strong>        "max_hours": 72,
</strong><strong>        "min_days": 2,
</strong><strong>        "max_days": 3,
</strong>        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "reference_origin": null,
        "metadata": {}
      },
      "relationships": {
        "stock_location": {
          "links": {...}
        },
        "shipping_method": {
          "links": {...}
        },
        "attachments": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    }
  ]
}
</code></pre>

{% endtab %}
{% endtabs %}

The image below shows how the displayed information about the selected shipping method is mapped to specific relationships of the shipment object.

![A sample selected shipping method delivery lead times mapping](https://2610849379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lk-ezuDClaMavTqnRi0%2Fuploads%2F9sd8KA9I4sgBnUJKRvuQ%2Fselected-shipping-method-mapping.jpg?alt=media\&token=6f2c6a81-52ad-4d39-ba4e-db4018292261)

## Additional notes

#### Purchasing gift cards

When purchasing digital products — i.e. gift cards — no shipments are created for the order, therefore the order can be placed without any shipping method.

#### Default shipping method

If you set a [default shipping method for a market](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/markets#default-shipping-method), all the shipments that belong to the market's orders and that are not already associated with a shipping method will be automatically associated with the default one. In particular, any new shipment will be automatically associated with the default shipping method at creation time and the default shipping method will be listed among the [shipment's available shipping methods](#id-1.-get-the-available-shipping-methods). Of course, you can always change the shipping method by [patching the shipment](#id-3.-select-a-shipping-method) and updating the relationship.

## More to read

See our documentation if you need more information about the [shipping method](https://docs.commercelayer.io/developers/v/api-reference/shipping_methods), [delivery lead time](https://docs.commercelayer.io/developers/v/api-reference/delivery_lead_times), and [gift card](https://docs.commercelayer.io/developers/v/api-reference/gift_cards) objects or on how to [update](https://docs.commercelayer.io/developers/v/api-reference/shipments/update) and [retrieve a shipment](https://docs.commercelayer.io/developers/v/api-reference/shipments/retrieve) or [include associations](https://docs.commercelayer.io/developers/including-associations).
