Transfer Shipping Rate script to Shopify Functions

So I would like to build the specific discount functions. At the moment, our client has many inventory locations.
So when we add to cart several products, if the inventory locations of the cart items are different vs each other, Shipping rates would be increased.
For example: There are 2 line items on the cart and their inventory locations are different from each other.
if Shipping rates is $12.25, then $24.5 would be applied for shipping rate. This is the reason why we had resolved this issue using the Shopify Script. But since Shopify Scripts are sunsetting, we need to use functions with extensibility to resolve this.

if(Input.cart.line_items.length > 1)
  Input.shipping_rates.each do |shipping_rate|
    target_shipping_option = shipping_rate.name
    target_shipping_rule = []
    matching_rule = SHIPPING_RATE_RULES.find do |rule|
      if (rule[:name] == target_shipping_option && target_condition >= Money.new(cents: rule[:condition][0]) && target_condition <= Money.new(cents: rule[:condition][1]))
        target_shipping_rule = rule
      end
    end
    puts(target_shipping_rule)
    if (shipping_rate.price != Money.new(cents: target_shipping_rule[:price]))
      discounted_amount = shipping_rate.price - Money.new(cents: target_shipping_rule[:price])
      SHIPPING_FROM_ONE_LOCATION = false
      shipping_rate.apply_discount(discounted_amount, message: "Original shipping with two locations")
    end
  end
end
if(dropshipped > 0)  
  Output.shipping_rates = Input.shipping_rates.delete_if {|shipping_rate| !shipping_rate.name.include?("Standard Shipping") && !shipping_rate.name.include?("Alaska, Hawaii")}
else
  # Customized Bra Collection
  if(numberOfMatchesCustomizedBras > 100)
    Output.shipping_rates = Input.shipping_rates.delete_if {|shipping_rate| !shipping_rate.name.include?("Standard Shipping") && !shipping_rate.name.include?("Alaska, Hawaii")}
  end
end
# Default return
Output.shipping_rates = Input.shipping_rates

^^ This is the script we’d like to add to functions.

Hi @wantokii

As I understand, it’s not possible to increase shipping rates with Scripts. Is your script actually doing a decrease/discount based on this condition? In that case, you can use the Shipping Discount API to accomplish the same.

-Nick