Such a search can be performed to ensure that a starship or its cargo are free of a virus or other potential unhealthful contaminants in order to prevent their spread outside a particular area. Depending on what is being searched, it can take up to six hours to complete. Being a lawful search, it can be used as a cover to search for evidence of illegal activities like smuggling.
That was the case in 2372 when Odo attempted to perform a Class 2 inspection of the Xhosa, operated by Kasidy Yates. He claimed that an outbreak of Temecklian virus on Bajor required him to search all vessels docked at Deep Space 9 to ensure that it was free of the virus, whether or not any of the cargo actually came from Bajor. His true motive in searching her vessel, however, was to search for evidence of smuggling to the Maquis. Yates was able to evade the search by using her personal relationship with DS9 commander Benjamin Sisko to delay it. When the search finally did take place, no evidence of smuggling was found. (DS9: "For the Cause")