bpmscript 2.0 coming soon

  /** loan broker **/
  requestBestRate: function(request) {

    // create a new service for calling remote services asynchronously
    var loanBrokerService = new LoanBrokerService(this.channel);
    
    // get the credit score, 5 minute timeout
    var creditScore = loanBrokerService.getCreditScore(request.ssn, time.minutes(5));
    
    // find out which banks can service this loan    
    var banks = loanBrokerService.getBanks(request.amount, creditScore.score, creditScore.hlength, time.minutes(5));
    
    // go through and call each bank in parallel
    var futures = [];
    for(var i = 0; i < banks.length; i++) {
      futures.push(loanBrokerService.getQuoteAsync( 
        banks[i], request.amount, creditScore.score, 
        creditScore.hlength, request.ssn, request.term));
    }
    
    // get the responses from each bank and work out
    // which one is best
    var best = {};
    for(var i = 0; i < futures.length; i++) {
      var rate = futures[i].get(time.days(3));
      if(best.rate == null || best.rate < rate) {
          best.rate = rate;
          best.bank = banks[i];
      }
    }

    // send the best rate and bank back to the customer
    return best;
  }