# Supplier Inbound Delivery Weather Risk Insights

This consumption data product sample extends
[Supplier and Plant Weather Risk Insights](https://docs.cloud.google.com/cortex/docs/solution-samples/supplier-plant-weather-risk-insights.md.txt)
with multimodal ocean-carrier telemetry from **Dun \& Bradstreet (D\&B) Global
Shipping Insights** and **Google WeatherNext 3** ensemble forecasts subscribed
through
[BigQuery sharing](https://docs.cloud.google.com/cortex/docs/source-system-integration/analytics-hub.md.txt).
It maps SAP inbound deliveries across physical logistics nodes---the maritime port
of loading (or the geocoded terrestrial supplier origin when no departure
seaport resolves), the port of discharge, and the receiving SAP plant---to
quantify ocean transit delays, port dwell bottlenecks, and severe weather
exposure.

With this sample, you can:

- Link SAP inbound deliveries to ocean Bills of Lading, vessel milestone timestamps (`vessel_departure_time`, `vessel_arrival_time`, `vessel_unload_time`), and UN/LOCODE ports of loading and discharge without row fan-out using a four-tier matching cascade. Direct matching on `bill_of_lading_bolnr` (`LIKP-BOLNR`) requires maritime mode or ocean Incoterms; D\&B shipper-history and origin-to-destination trade-corridor tiers apply only to cross-border maritime or intermodal deliveries, so domestic and non-BOL Road, Rail, or Air routes resolve to `SAP_HISTORICAL_FALLBACK`.
- Evaluate port infrastructure constraints---such as harbor size, channel and cargo-pier depth, and tide range---across global seaports from the United States National Geospatial-Intelligence Agency (NGA) World Port Index.
- Overlay 72-hour WeatherNext 3 ensemble forecasts within a configurable spatial radius (25 km by default) across departure ports (or the terrestrial supplier origin geocoded from `world_city_directory` when no departure seaport resolves), destination ports, and receiving plants to pinpoint weather-driven port closures, supplier dispatch risks, and inbound delivery delays.

## Reference architecture

A high-level reference architecture provides an overview of the source-specific
data products required to feed this use case.

[![Supplier Inbound Delivery Weather Risk Insights consumption data product sample reference architecture for Cortex Framework](https://docs.cloud.google.com/static/cortex/docs/images/cortex7_solution_samples_bdc.png)](https://docs.cloud.google.com/static/cortex/docs/images/cortex7_solution_samples_bdc.png)
**Figure 1**. Supplier Inbound Delivery Weather Risk Insights consumption data product sample reference architecture for Cortex Framework.

## Published data assets

Deploying the Supplier Inbound Delivery Weather Risk Insights module creates the
following BigQuery tables and views in your target dataset:

| Data asset | Materialization | Primary key grain | Description |
| `supplier_inbound_delivery_weather_risk_insights` | `View` | `delivery_document`, `delivery_document_item` | Multimodal consumption view enriching `inbound_delivery_insights` with D\&B Bill of Lading carrier attributes and vessel milestone timestamps (`vessel_departure_time`, `vessel_arrival_time`, `vessel_unload_time`), empirical ocean transit and port dwell durations (with shipper and trade-corridor tiers gated to cross-border maritime or intermodal deliveries, so domestic and non-BOL Road, Rail, or Air routes resolve to `SAP_HISTORICAL_FALLBACK`), NGA harbor physical limits, and multi-node WeatherNext 3 ensemble forecasts across the departure port (falling back to the terrestrial supplier origin from `world_city_directory` when no departure seaport resolves), destination port, and receiving plant. |
| `world_port_index_directory` | `Table` | `unlocode` | Reference table of global seaports from the US NGA World Port Index (Publication 150) with standardized UN/LOCODE keys, WGS84 coordinates, precomputed BigQuery `GEOGRAPHY` points, and harbor depth and shelter attributes. |
|---|---|---|---|

## Required upstream products and catalog sources

Before enabling this sample, configure the following dependencies:

- **Base data product (`supplierPlantWeatherRiskInsights`)** : Enable [Supplier and Plant Weather Risk Insights](https://docs.cloud.google.com/cortex/docs/solution-samples/supplier-plant-weather-risk-insights.md.txt) (`inbound_delivery_insights` and `world_city_directory`).
- **Dun \& Bradstreet Global Shipping Insights (`analytics_hub`)** : Subscribe to the Dun \& Bradstreet shipping insights listing in BigQuery sharing and include `shipping_insights` in `inlineTableSettings.tables` of an `analytics_hub` catalog module.
- **Google WeatherNext 3 (`analytics_hub`)** : Subscribe to the Google WeatherNext 3 listing in BigQuery sharing and include `weathernext_3_0_0` in `inlineTableSettings.tables` of an `analytics_hub` catalog module.

For catalog subscription and validation details, see
[BigQuery sharing integration](https://docs.cloud.google.com/cortex/docs/source-system-integration/analytics-hub.md.txt).

## Enable the data product in `config/config.yaml`

Register your Dun \& Bradstreet and Google WeatherNext `analytics_hub` catalogs
alongside your SAP BDC catalog, ensure
`supplier_plant_weather_risk_insights` is enabled, and add
`supplier_inbound_delivery_weather_risk_insights` under
`data.modules.products`:

```yaml
data:
  namespaces:
    - name: cortex
    - name: cortex_samples

  modules:
    catalogs:
      # Include sap_bdc_catalog from Supplier and Plant Weather Risk Insights.
      # Dun & Bradstreet Global Shipping Insights linked dataset.
      - id: ah_dnb_catalog
        type: analytics_hub
        bindsNamespaces: [cortex.external.dnb]
        connectionSettings:
          projectId: LINKED_DATASET_PROJECT_ID
          datasetId: DNB_DATASET_ID
          location: US
        inlineTableSettings:
          tables:
            - shipping_insights

      # Google WeatherNext 3 linked dataset.
      - id: ah_weathernext_catalog
        type: analytics_hub
        bindsNamespaces: [cortex.external.weathernext]
        connectionSettings:
          projectId: LINKED_DATASET_PROJECT_ID
          datasetId: WEATHERNEXT_DATASET_ID
          location: US
        inlineTableSettings:
          tables:
            - weathernext_3_0_0

    products:
      # Upstream base sample product (required).
      - moduleId: supplier_plant_weather_risk_insights
        enabled: true
        modulePath: cortex_samples.sap_bdc.products.supplier_plant_weather_risk_insights
        dataTargetId: samples_target
        dependencyBindings:
          sapBdcPurchaseOrder: sap_bdc_catalog.purchaseorder
          sapBdcSupplier: sap_bdc_catalog.supplier
          sapBdcPlant: sap_bdc_catalog.plant
          sapBdcAddress: sap_bdc_catalog.address
          sapBdcProduct: sap_bdc_catalog.product
          sapBdcCompany: sap_bdc_catalog.company
          sapBdcDeliveryHeader: sap_bdc_catalog.delivery_header
          sapBdcDeliveryItem: sap_bdc_catalog.delivery_item
          weatherNext: ah_weathernext_catalog.weathernext_3_0_0

      # Enabled Supplier Inbound Delivery Weather Risk Insights sample.
      - moduleId: supplier_inbound_delivery_weather_risk_insights
        enabled: true
        modulePath: cortex_samples.sap_bdc.products.supplier_inbound_delivery_weather_risk_insights
        dataTargetId: samples_target
        dependencyBindings:
          supplierPlantWeatherRiskInsights: supplier_plant_weather_risk_insights
          dnbShipping: ah_dnb_catalog.shipping_insights
          weatherNext: ah_weathernext_catalog.weathernext_3_0_0
        inlineTableSettings:
          supplier_inbound_delivery_weather_risk_insights:
            filters:
              schedule_variance_thresholds:
                extended_port_dwell_threshold_days: 4.0
              weather_thresholds:
                forecast_horizon_hours: 72
                spatial_radius_meters: 25000
```

Replace the following:

- `LINKED_DATASET_PROJECT_ID`: the Google Cloud project ID hosting the subscribed BigQuery sharing linked datasets, for example: `my-cortex-project`.
- `DNB_DATASET_ID`: the BigQuery dataset ID of your subscribed Dun \& Bradstreet Global Shipping Insights listing, for example: `dnb_global_shipping_insights`.
- `WEATHERNEXT_DATASET_ID`: the BigQuery dataset ID of your subscribed Google WeatherNext 3 listing, for example: `google_weathernext_3`.

For the complete set of configurable `critical_material_types`,
`schedule_variance_thresholds` (including `extended_port_dwell_threshold_days`),
and `weather_thresholds` options under `inlineTableSettings` or `tableSettings`,
see
`src/data_modules/cortex_samples/sap_bdc/products/supplier_inbound_delivery_weather_risk_insights/table_settings.default.yaml`.

Build and deploy the configured sample:

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-build-and-deploy --config $CORTEX_CONFIG_FILE
```

## Entity-relationship diagram

You can view the Entity-Relationship (ER) diagram in the module's `README.md` or
generate it from your compiled workspace using
[`uv run cortex-metadata erd`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-metadata.md.txt#erd):

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-metadata erd \
  --config $CORTEX_CONFIG_FILE \
  --module-id supplier_inbound_delivery_weather_risk_insights
```

## Source code

Explore the SQL models, `manifest.yaml`, and annotations in the repository at
[`src/data_modules/cortex_samples/sap_bdc/products/supplier_inbound_delivery_weather_risk_insights`](https://github.com/GoogleCloudPlatform/cortex-framework/tree/main/src/data_modules/cortex_samples/sap_bdc/products/supplier_inbound_delivery_weather_risk_insights).

## Enable AI agents

After materializing `supplier_inbound_delivery_weather_risk_insights` in
BigQuery, you can enable the prebuilt **SAP Inbound Logistics
Risk Agent** (`cortex-sap-inbound-logistics-risk-analyst`) in `config/config.yaml`
and provision it with
[`uv run cortex-create-ca-agents`](https://docs.cloud.google.com/cortex/docs/conversational-analytics.md.txt#prebuilt-agent-templates),
or [create a custom data agent](https://docs.cloud.google.com/bigquery/docs/create-data-agents.md.txt) in
BigQuery Studio to ask questions about ocean port congestion, vessel gales or
swell cutoffs, and multimodal inbound delivery risks.

## What's next

- [Solution samples overview](https://docs.cloud.google.com/cortex/docs/solution-samples/overview.md.txt)
- [Supplier and Plant Weather Risk Insights](https://docs.cloud.google.com/cortex/docs/solution-samples/supplier-plant-weather-risk-insights.md.txt)
- [SAP Business Data Cloud integration](https://docs.cloud.google.com/cortex/docs/source-system-integration/sap-bdc.md.txt)
- [BigQuery sharing integration](https://docs.cloud.google.com/cortex/docs/source-system-integration/analytics-hub.md.txt)