Show USPS Rate On Sales Header

SavatageSavatage Member Posts: 7,142
edited 2007-04-26 in Navision Attain
We ship many small internet orders via US Mail. We've been setting up all kinds of software to simplify the process & now my brain is fried!

All orders over 20 lbs will go UPS - e-ship takes care of that.

I have created a chart of all zip codes in US and what their postage will be by pound. This table will be 50010 USPS Rate table.

See chart here
http://savatage99.googlepages.com/ZIPCO ... CHART1.xls

The goal is On Release of the order to show what the Mail rate will be.
So I need to get the Ship-To Zip Code (no prob) and calculate the order weight (rounded up). Now with these two fields I should be able to get the price from the new USPS rate table.

The rate table has a min & max zip per zone & weight. I need to setrange or filter - and would like some suggestions on the best way to accomplish this task.
TotalOrderWeight := ROUND(SalesHeader."Total Order Weight", 1, '>');

USPSRATETABLE.GET(SalesHeader."Ship-to ZIP Code",SalesHeader."Ship-To Zip Code", TotalOrderWeight);
If TotalOrderWeight < 21 
THEN 
 SETFILTER(USPSRateTable.ToMinZipCode,'>=%1',SalesHeader."Ship-To Zip CODE") ;
 SETFILTER(USPSRateTable.ToMaxZipCode,'<=%1',SalesHeader."Ship-To Zip Code");
 SETFILTER(USPSRateTable.Weight,'=%1',TotalOrderWeight);
 SalesHeader.USPSOrderPostage := USPSRateTabel.Price 
ELSE 
 SalesHeader.USPSOrderPostage := 0;
Am I in the ballpark here? or does somone know of a better way?

Answers

  • krikikriki Member, Moderator Posts: 9,115
    Try this:
    TotalOrderWeight := ROUND(SalesHeader."Total Order Weight", 1, '>');
    
    If TotalOrderWeight <= 20 THEN BEGIN
      USPSRATETABLE.RESET;
      USPSRATETABLE.SETCURRENTKEY(ToMinZipCode,ToMaxZipCode,Weight);
      USPSRATETABLE.SETRANGE(ToMinZipCode,'00000',SalesHeader."Ship-To Zip CODE") ;
      USPSRATETABLE.SETRANGE(ToMaxZipCode,SalesHeader."Ship-To Zip CODE",'99999') ;
      USPSRATETABLE.SETRANGE(Weight,TotalOrderWeight - 0.0001,TotalOrderWeight + 0.0001); // to avoid rounding problems when filtering
      IF USPSRATETABLE.FINDFIRST THEN // OR USPSRATETABLE.FIND('-');
        SalesHeader.USPSOrderPostage := USPSRateTabel.Price
      ELSE
        SalesHeader.USPSOrderPostage := 0;
    end;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • SavatageSavatage Member Posts: 7,142
    Kriki you are a god of Heavy Metal!!!

    A little tweaking and the final code used
    TotalOrderWeight := ROUND("Total Net Weight", 1, '>');
    IF "Ship-to Country Code" = 'US'
     THEN BEGIN
      IF TotalOrderWeight <= 20
       THEN BEGIN
        UspsRateTable.RESET;
        UspsRateTable.SETCURRENTKEY(ToMinZipCode,ToMaxZipCode,Weight);
        UspsRateTable.SETRANGE(ToMinZipCode,'00000',"Ship-to ZIP Code") ;
        UspsRateTable.SETRANGE(ToMaxZipCode,"Ship-to ZIP Code",'99999') ;
        UspsRateTable.SETRANGE(Weight,TotalOrderWeight - 0.0001,TotalOrderWeight + 0.0001);   
        IF UspsRateTable.FIND('-') THEN
        SalesHeader.UspsOrderPostage := UspsRateTable.Price
      ELSE 
        SalesHeader.UspsOrderPostage := 0; 
      END
    END;
    
  • krikikriki Member, Moderator Posts: 9,115
    At your service :D
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.