String findRoute( Map map, GeoLocation[] stops, double HWPref, int weight, boolean optimize)
Finds a route between the specified locations.

Parameters:
map - Map object;
stops - array of locations;
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 empty string.


public String findRoute( Map map, GeoLocation[] stops, double HWPref, int weight, boolean optimize) throws RMException
{
    RoutingProblem rProblem = map.getRouting().createRoutingProblem();
    RoutingStop rStop;

    for(int i=0; i < stops.length; i++)
    {
        rStop = new RoutingStop();
        rStop.setStop(new GeoPoint( stops[i].x, stops[i].y));
        rStop.setLabel(stops[i].label);
        rProblem.addStop(rStop);
    }
	
    if ( weight == RoutingProblem.QUICKEST)
    {
        rProblem.setHighwayPreference(HWPref);
        rProblem.setWeight(RoutingProblem.QUICKEST); // find quickest route
    }
    else
    {
        rProblem.setWeight(RoutingProblem.SHORTEST); // find shortest route
    }

    rProblem.setOptimize( optimize);

    String RouteID = map.getRouting().findRoute(rProblem, false, -1);

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

Example:
<%

    Map map = openMap( application);

    GeoLocation[] stops = new GeoLocation[4];

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

    String routeID = findRoute( map, stops, 50, RoutingProblem.SHORTEST, false);
    
    if( routeID != null)
        showRoute(map, routeID, out);

%>

<%!

public void showRoute( Map map, String routeID, JspWriter out) throws RMException, IOException
{
    Routing routing = map.getRouting();

    // show the route
    routing.setRoute( routeID);
    GeoRectangle r = routing.getDrivingDirections( routeID).getExtent();
    map.setExtent( inflateRect(r, 10)); // increase borders

    // print driving directions
    DrivingDirections dDirs = routing.getDrivingDirections( routeID);
    DirectionsSegment dSeg;
	
    out.println( "<p>" + dDirs.getStartText() + "<br>");
    out.println( dDirs.getFinishText() + "<br>");
    out.println( dDirs.getTotalText() + "<p>");

    for( int i=0; i < dDirs.getSegmentCount(); i++)
    {
        dSeg = dDirs.getSegment( i);
        out.println( (i+1) + ". " + dSeg.getText()+ "<br>");
        if( dSeg.getSegmentType() != DirectionsSegment.ARRIVE && dSeg.getSegmentType() != DirectionsSegment.DEPART) // if there is TimeLengthText
            out.println( dSeg.getTimeLengthText()+ "<br>");
    }

}

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

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

    return (r);
}

public class GeoLocation
{
    public String label;
    public double x;
    public double y;
    
    GeoLocation (Map map, String clabel, double clat, double clon) throws RMException
    {
        Projection proj = map.getProjection();
        GeoPoint pt = proj.project( clat, clon);
        
        label = clabel;
        x = pt.x;
        y = pt.y;
    }
}

%>

<img src="<%= map.getMapImageURL(map.getImageWidth(), map.getImageHeight(), ImageFormat.DEFAULT)%>"
width="<%=map.getImageWidth()%>" height="<%=map.getImageHeight()%>">