string findRoute( array stops, double HWPref, integer weight, boolean optimize)
Finds a route between the specified locations.

Parameters:
stops - array of locations (any valid object with x, y, and label fields);
HWPref - highway preference (0-100);
weight - route preference (quickest or shortest);
optimize - enables or disables the optimizing route parameter (also known as the "Traveling Salesman Problem").

Returns:
Route ID string or null.


function findRoute( stops, HWPref, weight, optimize)
{
    var rProblem = Map.getRouting().createRoutingProblem();
    var rStop;

    for(var i=0; i < stops.length; i++)
    {
        rStop = Server.CreateObject("RMIMS.RoutingStop");
        rStop.setStop(createPoint( stops[i].x, stops[i].y));
        rStop.setLabel(stops[i].label);
        rProblem.addStop(rStop);
    }
	
    if ( weight == rmQuickest )
    {
        rProblem.setHighwayPreference(HWPref);
        rProblem.setWeight(rmQuickest); // find quickest route
    }
    else
    {
        rProblem.setWeight(rmShortest); // find shortest route
    }

    rProblem.setOptimize( optimize);

    var RouteID = Map.getRouting().findRoute(rProblem, false, -1);

    if( RouteID == "") RouteID = null;
	
    return RouteID;
}

function createPoint(x, y)
{
    var pt = Server.CreateObject("RMIMS.GeoPoint");
    pt.x = x;
    pt.y = y;

    return pt;
}

Example:
var stops = new Array();
stops[0] = new GeoLocation( "Redlands, CA", 34.0528, -117.1531);
stops[1] = new GeoLocation( "Loma Linda, CA", 34.0484, -117.2629);
stops[2] = new GeoLocation( "San Bernardino, CA", 34.1214, -117.3046);
stops[3] = new GeoLocation( "Highland, CA", 34.1282, -117.2106);

var RouteID = findRoute( stops, 50, rmShortest, false);
if( RouteID != null)
    showRoute(RouteID);

function showRoute( RouteID)
{
    var Routing = Map.getRouting();

    Routing.setRoute( RouteID);
    var r = Routing.getDrivingDirections( RouteID).getExtent();
    Map.setExtent( inflateRect(r, 10));

    // print driving directions
    var DDirs = Routing.getDrivingDirections( RouteID);
    var DSeg;
	
    Response.Write( "<p>"+DDirs.getStartText()+"<br>\n");
    Response.Write( DDirs.getFinishText()+"<br>\n");
    Response.Write( DDirs.getTotalText()+"<p>\n");

    for( var i =0; i < DDirs.getSegmentCount(); i++)
    {
        DSeg = DDirs.getSegment( i);
        Response.Write( (i+1)+". " + DSeg.getText() + "<br>\n");
        // if there is TimeLengthText
        if( DSeg.getSegmentType() != rmArrive && DSeg.getSegmentType() != rmDepart)
            Response.Write( DSeg.getTimeLengthText() + "<br>\n");
    }
}

function GeoLocation( label, lat, lon)
{
    var pt = Map.getProjection().project( lat, lon);
    this.label = label;
    this.x = pt.x;
    this.y = pt.y;
}

function inflateRect(r, percVal)
{
    var dx = ((r.right - r.left) * percVal) / 100.0;
    var dy = ((r.top - r.bottom) * percVal) / 100.0;

    r.left   -= dx;
    r.top    += dy;
    r.right  += dx;
    r.bottom -= dy;

    return r;
}