Skip to content

Latest commit

 

History

History
135 lines (80 loc) · 7.53 KB

inventory-configure-distance-priority.md

File metadata and controls

135 lines (80 loc) · 7.53 KB
title redirect_to
Configuring Distance Priority Algorithm

The Distance Priority Algorithm compares the location of the shipping destination address with source locations to determine the closest source to fulfill shipments. The distance may be determined by physical distance or time spent traveling from one location to another, using database data or driving, walking, or bicycling directions. Use this [Source Selection Algorithm]({% link catalog/inventory-about-ssa.md %}) to recommend the closest source to shipping destination addresses.

{:.bs-callout-info} We recommend entering the full street address and GPS coordinates for your [sources]({% link catalog/inventory-sources-add.md %}) if using the Distance Priority Algorithm.

You have two options for calculating the distance and time to find the closest source for shipment fulfillment:

  • Google MAP - Uses Google Maps Platform services to calculate the distance and time between the shipping destination address and source locations. This option uses the source's Latitude and Longitude (GPS coordinates) and may use the street address depending on the computation mode. You must provide a Google API key with Geocoding API and Distance Matrix API enabled, and you may incur charges through Google.

  • Offline Calculation - Calculates the distance using downloaded and imported geocode data using zip/post codes and GPS coordinates to determine the closest source to the shipping destination address. To configure this option, you may require developer assistance to initially download and import geocodes using command line instructions.

{:.bs-callout-info} For multi-store website with several countries, configure [Default Tax Destination]({% link tax/tax-destination-default.md %}) for each country.

Configure Google Maps

You do not need a Google account to get started. The process includes Google account and project creation, if needed. This option requires a billing account and payment method added to your Google account to complete configurations and use the algorithm. However, Google MAP distance-based algorithm is recommended as more advanced and precise in comparison to Offline Calculation.

Step 1: Create the Google API key

The key is from the Google Maps Platform and should have Geocoding API and Distance Matrix API enabled. For details, see [Configuring Distance Priority Algorithm]({% link catalog/inventory-configure-distance-priority.md %}).

  1. Visit Google Maps Platform and click Get Started.

  2. To enable the platform, select Maps, Routes, and Places and click Continue.

    ![]({% link catalog/assets/inventory-google-key1.png %}){: .zoom} Google Maps Platform for your Key

  3. Sign in with a Google account or create a new account.

  4. Set up a project:

    • Select a project or enter a new project name.

    • Select Yes to accept the terms.

    • Click Next.

  5. Enter a billing account or create one. You can skip and add a billing account later.

    A billing account is required to use this service.

  6. Click Console to open and configure your Google Cloud Platform options.

    • Open your project.

    • Expand the menu and click APIs & Services > Library.

      ![]({% link catalog/assets/inventory-google-key2.png %}) Google API Services

    • Search for Geocoding API and Distance Matrix API. Select and enable each service.

  7. Expand the menu, click APIs & Services > Credentials, and copy the Google API Key.

    ![]({% link catalog/assets/inventory-google-key3.png %}){: .zoom} Google API Key Copy

Step 2: Configure the Google MAP Provider

  1. On the Admin sidebar, go to Stores > Settings > Configuration.

  2. In the left panel, expand Catalog and choose Inventory.

  3. Expand ![]({% link assets/icon-display-expand.png %}) the Distance Provider for Distance Based SSA section and set Provider to Google MAP.

    ![]({% link configuration/catalog/assets/catalog-inventory-distance-provider.png %}){: .zoom} Distance Providers for Distance Based SSA

  4. Expand ![]({% link assets/icon-display-expand.png %}) the Google Distance Provider section and configure the settings:

    • For Google API Key, enter the key copied from your Google Account.

    • For Computation mode, select a configuration.

      {:.bs-callout-info} When using this algorithm for shipping, if routes and data do not return for the selected Computation mode (driving, bicycling, or walking) for a shipment, the SSA defaults to using the Source Priority. We recommend also setting the [priority for sources per stock]({% link catalog/inventory-stock-priority.md %}).

      | Driving | (Default) Requests standard driving directions using the road network. | | Walking | Requests walking directions using pedestrian paths and sidewalks (where available). | | Bicycling | Requests bicycling directions using bicycle paths and preferred streets (where available). The Distance Matrix Service is currently only available in the US and some Canadian cities. |

    • For Value, select a value type:

      | Distance | (Default) Returns the distance between points in metrics (kilometers and meters) or imperial (miles and feet). | | Time to Destination | Returns the time required to travel from the source locations to the shipping address in hours and minutes. |

    ![]({% link configuration/catalog/assets/catalog-inventory-distance-provider-settings.png %}){: .zoom} Google Distance Provider

  5. When complete, click Save Config.

Configure offline calculation

Offline calculations use country codes to determine the distance between the shipping destination and source addresses. This option may require developer assistance to configure. You will need to issue an Inventory Management CLI command to download and import data from geonames.org.

{:.bs-callout-info} Imported geocodes from geonames.org have limitations for some countries like Canada, Ireland, etc. Please refer to [GeoNames Postal Code files][7] for more information.

Step 1: Download and import geocodes

Complete command line configuration to download and import geocodes countries to ship to and have source locations in. This step may require developer assistance for help with command line tasks. Refer to [Import geocodes][6].

Complete these commands anytime you need to add more geocodes.

Step 2: Set the calculation

  1. On the Admin sidebar, go to Stores > Settings > Configuration.

  2. In the left panel, expand Catalog and choose Inventory.

  3. Expand ![]({% link assets/icon-display-expand.png %}) the Distance Provider for Distance Based SSA section.

  4. Deselect the Use system value checkbox and set Provider to Offline Calculation.

    ![]({% link catalog/assets/inventory-distance-offline.png %}){: .zoom} Distance Providers for Distance Based SSA

  5. When complete, click Save Config.

[6]: {{ site.devdocs_url }}/guides/v{{ site.version }}/inventory/inventory-cli-reference.html#import-geocodes [7]: https://download.geonames.org/export/zip/readme.txt