One more thing you should get used to when switching to and fro BaanERP is that BaanERP uses UTC (Universal Time Coordinated). So in your case, I'd expect the program to give unexpected result, because you used the date.num() function while calculating value to pass to dldt.f and dldt.t (which are in UTC). Please read the Tools on line help to learn more about UTC.
To cut story short, when passing values to a from/to date/time in BaanERP, I usually send utc.num()-7*24*60*60 (i.e. exactly 7 days before the current date & time) to the from field and send utc.num()+7*24*60*60 to the to field. Use this approach and your API program should work better in BaanERP (provided the planned delivery date is +/- 1 week from current date & time)